【问题标题】:iOS Push notifications using cordova. The notification is never received使用 cordova 的 iOS 推送通知。从未收到通知
【发布时间】:2019-04-06 19:49:21
【问题描述】:

我创建了一个使用“phonegap-push-plugin”的示例 Cordova 应用程序。 该应用程序没有任何复杂性。在“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 设备上正确启用。我错过了什么?

更新:

  • 直接访问 Apple 的 APN(是的...没有 FCM!)
    我想通过 FCM 发送推送通知,但为了确定上述问题的原因,我决定直接尝试 APN。为此,我必须从应用程序的 config.xml 中删除 ,以便phonegap-push-plugin 可以从 APN 而非 FCM 获取令牌。

现在,使用新令牌和使用 node-apn 模块与 APN 服务器通信的服务器,我可以向我的 iOS 应用程序发送推送通知。这样做的缺点是我失去了推送主题的能力,因为这是FCM only feature.

我唯一不知道的是如何使用topic 来定位APN 网络中通过push.subscribe() 方法订阅的设备。

查看我的问题here

对此也有任何帮助吗?

【问题讨论】:

    标签: ios cordova push-notification


    【解决方案1】:

    所以,事实证明推送插件存在问题。

    此问题仅影响使用 FCM 的 iOS 设备应用上的用户。 如果您使用 APN,它就可以工作。

    你可以在这里查看我的答案:https://github.com/phonegap/phonegap-plugin-push/issues/2644#issuecomment-445346335

    我最初的问题报告在这里: https://github.com/phonegap/phonegap-plugin-push/issues/2613

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-19
      • 2011-08-23
      • 2017-11-19
      • 2017-05-28
      相关资源
      最近更新 更多