【发布时间】:2017-11-17 07:28:20
【问题描述】:
我已按照这些说明在 iOS 上使用 Firebase 设置推送通知。我很确定我已经正确设置了所有 Apple 证书,并且可以很好地从 FCM(Firebase 云消息传递)发送通知,并且状态为“已发送”,但它们从未到达我的 iPhone。
https://ionicframework.com/docs/native/push/
这是我的代码。任何建议为什么这不起作用或如何调试它将不胜感激!非常感谢!
import { Push, PushObject, PushOptions } from '@ionic-native/push';
constructor(platform: Platform, private push: Push, public alertCtrl: AlertController) {
platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
this.pushNotifications();
});
}
pushNotifications() {
this.push.hasPermission().then((res: any) => {
if (res.isEnabled) { console.log('We have permission to send push notifications');}
else { console.log('We do NOT have permission to send push notifications'); }
}).catch((error) => { console.log("Push Notification needs Cordova: " + JSON.stringify(error));});
const options: PushOptions = {
android: {
senderID: 'My_ID'
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
if(notification.additionalData.foreground) {
let youralert = this.alertCtrl.create({
title: 'New Push notification',
message: notification.message
});
youralert.present();
}
});
pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', JSON.stringify(registration)));
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
【问题讨论】:
-
您是否尝试将有效负载
priority设置为high? -
@AL。我该怎么做?谢谢!
-
它实际上是在 Firebase 中默认设置的。所以不,不幸的是,这无济于事。
-
我对原生推送插件有类似的问题。然后我迁移到 ionic-native fcm 插件 (ionicframework.com/docs/native/fcm)。这个 fcm 插件可以正常工作。
标签: ios firebase push-notification ionic2 firebase-cloud-messaging