我正在尝试在使用Ionic 3开发的应用中实现推送通知。我正在关注本教程:https://medium.com/@ankushaggarwal/generate-apns-certificate-for-ios-push-notifications-85e4a917d522
Android的一切进展顺利,我收到通知。
但是,在iOS上,当我发送推送通知时,我在iOS上一无所获。
我做了以下事情:
我的代码与上面教程中的代码相同:
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实现推送通知方面取得了成功?
感谢。
答案 0 :(得分:0)
您需要通过Apple的testflight或App store运行您的应用。根据我的经验,如果您只是在手机上本地运行应用程序,推送通知就不起作用。