@JackyVip wrote:
Hi i am using phonegap-plugin-push for notification, but i don’t receive any notifications foreground or background. On last build the notifications were working.
I send the notifications on gateway.push.apple.com on server side.
Here is my code:
import { Component, NgZone } from '@angular/core'; import { Platform } from 'ionic-angular'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; import { Push, PushObject, PushOptions } from '@ionic-native/push'; import { Auth } from '../providers/auth/auth'; import { Orders } from '../providers/orders/orders'; import { App } from 'ionic-angular/components/app/app'; import { LoginPage } from '../pages/login/login'; import { TabsPage } from '../pages/tabs/tabs'; @Component({ templateUrl: 'app.html' }) export class MyApp { rootPage:any = LoginPage; constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private push: Push, private auth:Auth, private ordersService:Orders, private appCtrl:App, private zoneCtrl:NgZone) { platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. statusBar.styleDefault(); statusBar.overlaysWebView(false); //statusBar.hide(); splashScreen.hide(); const options: PushOptions = { ios: { alert: 'true', badge: true, sound: 'true' } }; let appNav = this.appCtrl.getRootNavs(); const pushObject: PushObject = this.push.init(options); pushObject.on('registration').subscribe((registration: any) => { console.log('Device registered', registration.registrationId); if(platform.is('ios')) { auth.credentials.device = 'iOS'; auth.credentials.device_token = registration.registrationId; } else if(platform.is('android')) { auth.credentials.device = 'android'; auth.credentials.device_token = registration.registrationId; } else { auth.credentials.device = 'Simulator'; auth.credentials.device_token = ''; } } ); pushObject.on('notification').subscribe((notification: any) =>{ console.log('Received a notification', notification); if(platform.is('ios')) { console.log(notification.additionalData.foreground); if (notification.additionalData.foreground) { // If your user is using the app // Do something like opening the Post within the app // You have access to // notification.id which is the new Post ID // notification.alert which is the new Post Title this.ordersService.GetOrders(); console.log("foreground!"); } else { // If your user has clicked on the notification // Do something like opening the Post within the app // You have access to // notification.payload.id which is the new Post ID // notification.payload.message which is the new Post Title if(auth.credentials.token) { this.zoneCtrl.run(() =>{ if(appNav.length>0) { appNav[0].setRoot(TabsPage); } else { this.appCtrl.getRootNav().setRoot(TabsPage); } }); this.ordersService.GetOrders(); } else { this.appCtrl.getRootNav().setRoot(LoginPage); } } } }); pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error)); }); } }
Posts: 1
Participants: 1