FCM推送通知在两种设备上均能正常工作,唯一缺少的是,用户单击通知后,我需要打开一个特定页面,即使此功能在Android设备上也能正常工作,但在iO上并不需要它只是启动应用程序的页面。
我已经包括所有证书,并且满足了FCM中的所有其他要求,以使通知能够正常工作,我处于开发模式。
我的app.component.ts
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { FCM } from '@ionic-native/fcm/ngx';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private fcm: FCM,
private router: Router
) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
this.fcm.getToken().then(token => {
console.log(token);
});
this.fcm.onTokenRefresh().subscribe(token => {
console.log(token);
});
this.fcm.onNotification().subscribe(data => {
console.log(data);
if (data.wasTapped) {
console.log('Received in background');
this.router.navigate([data.landing_page, data.id]);
} else {
console.log('Received in foreground');
this.router.navigate([data.landing_page, data.id]);
}
});
}
}
JSON请求 https://fcm.googleapis.com/fcm/send
{
"notification":{
"title":"Test App",
"body":"Special Campaign",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
"data":{
"landing_page":"campaign-detail",
"id":"1034"
},
"to":"SAMPLE-TOKEN:APA91bE7JPTYOc4OdSZ50YyY-D2ghOOtfgdUzOYSd0JfNUaiBIDIcnUqzcObT-LzSorX3bplRcYpzrO3C-63fcUt25ZUuonCOlUaYnc7o3iqYcAasdfEdsulZfQy6d-bI58tcj",
"priority":"high"
}
如果我在Android上单击通知,则会将我带到所需页面,但是在iOs上,我会收到通知,但是当我单击它时,它会启动该应用程序,而不会带我到该页面Campaign-detail / 1034。