【问题标题】:How to send silent push to iOS via Google Cloud Messaging如何通过 Google Cloud Messaging 向 iOS 发送静默推送
【发布时间】:2015-08-17 10:32:28
【问题描述】:

如何通过 GCM 向 iOS 应用程序发送静默推送通知?

静默推送是不会出现在通知中心的通知,而是唤醒应用程序在后台执行一些操作。 Google 在新的GCM 中引入了新功能,可以向 Android、Chrome 和 iOS 发送推送消息。

任何想法,如何做到这一点?

【问题讨论】:

    标签: ios apple-push-notifications push google-cloud-messaging


    【解决方案1】:

    我正在使用node-gcm npm 库,以下有效负载适用于 iOS(对于 Android,我发送的有效负载略有不同):

    { dryRun: false,
      data: 
       { customKey1: 'CustomValue1',
         customKey2: 'CustomValue2',
         content_available: '1',
         priority: 'high' },
      notification: 
       { title: 'My Title',
         icon: 'ic_launcher',
         body: 'My Body',
         sound: 'default',
         badge: '2' } }
    

    当然,您需要确保您的应用可以处理入站通知。

    【讨论】:

      【解决方案2】:

      像这样使用content_available(不是content-available)属性:

      curl -X POST --header "Content-Type:application/json" --header "Authorization:key=AIzaXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "https://android.googleapis.com/gcm/send" --data-ascii '{"data":{"xxx":"yyy"},"content_available":true,"to":"XXXXXXXXXX:YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZZZZZZZZ"}'
      

      【讨论】:

      【解决方案3】:

      您需要从您的服务器将值为 1 的 content-available 属性添加到您的 aps 字典中。

      您需要通过在 Info.plist 文件中将 remote-notification 添加到 UIBackgroundModes 来为这些静默通知提供支持。更多详情here.

      【讨论】:

        猜你喜欢
        • 2016-11-03
        • 1970-01-01
        • 2014-02-21
        • 2016-03-05
        • 1970-01-01
        • 1970-01-01
        • 2020-12-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多