I nearly finished my Ionic App Development and it works perfectly fine on my Android Emulator (Pixel 2 XL, Android API 27). But When I deploy it to my phone, it results in several problems.
-
There should be a parent-child relationship in my dishdetail and menu page - when clicking on the picture on menu page, the user will be redirected to the dishdetail page. But this “click-redirect” action doesn’t work on my device.
-
There is also an option that the user is able to add a specific dish into the favorite list. Then the favorite list is stored externally in the device. However, when I open the favorites page, a “TypeError: Cannot Read Property ‘some’ of null” occurs and no data is loaded.
I suspect that the problem may lie in that the app is not able to get the storage on the device, so I deploy android-permissions to aid me with this. But it still doesn’t seem to work.
Below is my favorite.ts provider (the problem can only in the “this.favorites.some” part, right?).
imports...
@Injectable()
export class FavoriteProvider {
favorites: Array<any>;
constructor(public http: Http, private dishservice: DishProvider, private storage: Storage,
private localNotifications: LocalNotifications) {
console.log('Hello FavoriteProvider Provider');
this.favorites = [];
this.storage.get('favorites').then( favor => this.favorites = favor );
}
addFavorite(id: number): boolean {
if (!this.isFavorite(id))
this.favorites.push(id);
console.log('favorites', this.favorites);
this.storage.set('favorites', this.favorites);
this.localNotifications.schedule({
id: id,
text: 'Dish ' + id + ' added as a favorite successfully',
});
return true;
}
isFavorite(id: number): boolean {
return this.favorites.some(el => el === id);
}
getFavorites(): Observable<Dish[]> {
return this.dishservice.getDishes()
.map(dishes => dishes.filter(dish => this.favorites.some(el => el === dish.id)));
}
deleteFavorite(id: number): Observable<Dish[]> {
let index = this.favorites.indexOf(id);
if (index >= 0) {
this.favorites.splice(index, 1);
this.storage.set('favorites', this.favorites);
return this.getFavorites();
}
else {
console.log('Deleting non-existant favorite', id);
return Observable.throw('Deleting non-existant favorite' + id);
}
}
}
Ionic:
ionic (Ionic CLI) : 4.10.2 (C:\Users<Username>\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.2
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 11 other plugins)
System:
NodeJS : v10.14.1 (C:\Program Files\nodejs\node.exe)
npm : 6.4.1
OS : Windows 10
Please let me know if you need any further information.