我是ios的新手,我使用ionic2&创建了一个应用程序。 angular2需要集成推送通知,做了所有证书的东西,与FCM集成, 但无法接收通知。
以下是我的代码
initPushNotification() {
if (!this.platform.is('cordova')) {
alert('Push notifications not initialized. Cordova is not
available - Run in physical device');
return;
}
const options: PushOptions = {
android: {
senderID: 'testid'
},
ios: {
alert: 'true',
badge: false,
sound: 'true'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('registration').subscribe((data: any) => {
console.log('device token -> ' + data.registrationId);
});
pushObject.on('notification').subscribe((data: any) => {
alert('message -> ' + data.message);
//if user using app and push notification comes
if (data.additionalData.foreground) {
alert(data.message);
} else {
//if user NOT using app and push notification comes
//TODO: Your logic on click of push notification directly
//this.nav.push(DetailsPage, { message: data.message });
alert('Push notification clicked');
this.nav.setRoot(HomePage);
}
});
pushObject.on('error').subscribe(error => alert('Error with Push plugin' + error));
在上面的代码中,我可以使用pushObject.on(' registration')获取令牌,但是pushObject.on(' notification')没有被触发。
在xcode中我激活了推送功能。所以没有问题,
FCM中的某些内容我认为我失踪了,任何人都可以提供帮助