为什么我的离子iOS应用程序上没有任何推送通知?



我正在尝试在使用 Ionic 3 开发的应用程序中实现推送通知。我正在遵循本教程:https://medium.com/@ankushaggarwal/generate-apns-certificate-for-ios-push-notifications-85e4a917d522

Android一切顺利,我会收到通知。

但是,在iOS上,当我发送推送通知时,我在iOS上什么也得不到。

我做了以下工作:

  • 获取 APN 推送证书
  • 将其上传到我的离子帐户
  • 在 Xcode 的"功能"选项卡下切换了"推送通知">
  • 还在同一选项卡下打开了"后台模式/远程通知">

我的代码与上面教程中的代码相同:

initPushNotifications() {
if (!this.platform.is("cordova")) {
console.warn("Push notifications not initialized. Cordova is not available - Run in physical device");
return;
}
const options: PushOptions = {
android: {
senderID: "784098698049"
},
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);
this.userService.edit({
ionicToken: data.registrationId
});
});
pushObject.on("notification").subscribe((data: any) => {
console.log("message -> " + data.message);
//if user using app and push notification comes
if (data.additionalData.foreground) {
// if application open, show popup
let confirmAlert = this.alertCtrl.create({
title: "New Notification",
message: data.message,
buttons: [{
text: 'Ignore',
role: 'cancel'
}, {
text: 'View',
handler: () => {
//TODO: Your logic here
}
}]
});
confirmAlert.present();
} else {
//if user NOT using app and push notification comes
//TODO: Your logic on click of push notification directly
console.log('Push notification clicked');
}
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin' + error));
}

我还尝试遵循 https://docs.ionic.io/services/push/的官方文档,该文档不使用相同的模块。尽管如此,结果还是相同的:它适用于Android,但不适用于iOS。

我不知道我是否可以在某处找到一些日志,以确定是否存在错误。如果有人对此有信息,请分享。

有没有人在使用Ionic实现推送通知方面取得了任何成功?

谢谢。

您需要通过Apple的testflight或App Store运行您的应用程序。根据我的经验,如果您只是在手机上本地运行应用程序,推送通知将不起作用。

最新更新