[英]iOS Push notifications using cordova. The notification is never received
我創建了一個示例Cordova應用程序,它使用“ phonegap-push-plugin”。 該應用程序沒有任何復雜性。 在“ deviceready”上,我運行插件初始化代碼,如下所示:
var push = PushNotification.init({android: {}, ios: {
sound: true,
alert: true,
badge: true,
categories: {
invite: {
yes: {
callback: 'accept',
title: 'Accept',
foreground: true,
destructive: false
},
no: {
callback: 'reject',
title: 'Reject',
foreground: true,
destructive: false
},
maybe: {
callback: 'maybe',
title: 'Maybe',
foreground: true,
destructive: false
}
},
delete: {
yes: {
callback: 'doDelete',
title: 'Delete',
foreground: true,
destructive: true
},
no: {
callback: 'cancel',
title: 'Cancel',
foreground: true,
destructive: false
}
}
}
}})
push.on('notification', data => {
console.log(data.message);
console.log(data.title);
console.log(data.count);
console.log(data.sound);
console.log(data.image);
console.log(data.additionalData);
})
push.on('emailGuests', data => {
console.log('I should email my guests');
});
push.on('snooze', data => {
console.log('Remind me later');
});
push.on('registration', data => {
console.log(data.registrationId);
console.log(data.registrationType);
});
push.subscribe('xx', console.log)
這是日志輸出到控制台:
=> Successfully subscribe to topic xx
// The first run (after app install) will ask for permissions. If I click allow the lines below are printed to console.
=> dCAtjhCFBcU:APA91bG90c8VhNl_BzZ-2e9fmq_9fN6jfrRNJ1LPCRIpKnZ-AG-eLY4xtX84oJRZBh2D....KtNNQ35GM8ubPF5zr8HqeB6jffs
=> FCM
為了進行推送,我將以下負載發送到舊版服務器https://fcm.googleapis.com/fcm/send
。
{
"priority": "high",
"to": "/topics/xx", // I tried this but I also tried to specify the device token received upon "registration" event. I did this using to:<device_token> and also using registration_ids: [<device_token>].
"notification": {
"title": "My Message",
"body": "My Message Body",
"badge": 1,
"content-available": "1", // I tried with and without
"category": "identifier", // I tried with and without
"thread-id": "id", // I tried with and without
"sound": "default",
"icon": "default"
},
"data": {
"title": "A short string describing the purpose of the notification",
"body": "The text of the alert message",
"clubId": 1000
},
"notId": 1,
"custom_key1": "value1",
"custom_key2": "value2"
}
注意:我嘗試了與應用程序狀態有關的所有組合:后台應用程序; 應用已關閉; 應用程序在前台; 事件“通知”從未觸發,並且從未收到過推送通知。
當我使用主題時,發送到FCM服務器的請求將返回消息ID(這是可以理解的,因為其他設備訂閱了該主題)。 因此,已訂閱相同主題的android會收到該消息。 另一方面,iOS一無所獲!
{
"message_id": 5059997308576486332
}
如果我嘗試指定注冊時收到的令牌,則會收到一條略有不同的消息。 在大多數情況下,注冊時收到的令牌有效,並且結果將包含字符串ID。 但這是暫時的,因為幾分鍾后令牌變為“未注冊”。
{
"multicast_id": 88880398234xxxxx7,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "NotRegistered" // <-- This happens after a few minutes. I have to delete the app and reinstall it in order to get a new token.
}
]
}
這是構建配置
通知已在我的iOS設備上正確啟用。 我想念什么?
更新:
phonegap-push-plugin
可以從APN而不是從FCM獲取令牌。 現在,使用新令牌和使用node-apn
模塊與APN服務器通信的服務器,我可以向我的iOS應用發送推送通知。 不利的一面是,由於這是僅限FCM的功能 ,我失去了推送主題的能力。
我唯一仍然不知道的是如何使用該topic
來定位APN網絡中通過push.subscribe()方法訂閱的設備。
在這里查看我的問題。
也有任何幫助嗎?
因此,事實證明推插件存在問題。
此問題僅影響使用FCM的iOS設備應用程序上的用戶。 如果您使用APN,則可以使用。
您可以在這里查看我的答案: https : //github.com/phonegap/phonegap-plugin-push/issues/2644#issuecomment-445346335
我的最初問題報告在這里: https : //github.com/phonegap/phonegap-plugin-push/issues/2613
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.