【问题标题】:IOS GCM push notifications not working in backgroundIOS GCM 推送通知在后台不起作用
【发布时间】:2015-09-14 14:53:03
【问题描述】:

我正在努力让后台通知在带有 GCM 的 ios 上工作 - 非后台通知已经在工作。 在后台通知有时会来,有时不会。我用了 内容可用=真; 我也成功获得了Registration Token。

此代码功能性

$fields = array(
    'registration_ids' => $devices,
    'content_available' => true ,
    'notification' => array("title" => "title", "body"=>"body"),
    'data' => array("message"=>"hi")
);

但在后台没有收到通知。你能告诉我当应用程序在后台时 GCM 在 Ios 中不工作的确切原因吗???

【问题讨论】:

  • 您是否尝试过通过 Postman 或 curl 进行 HTTP 消息发送请求?您可以参考this StackOverflow answer了解更多详情。
  • 从php到IOS?我认为问题出在 IOS 端,您的发送请求看起来没问题。也许捕捉结果,看看它是否真的成功或给出错误。不确定你是否需要 content_available,我刚刚测试过,我的屏幕会随着通知亮起。
  • 那么您的iOS应用现在可以成功接收推送通知了吗?甚至您的应用也在后台?
  • 感谢您的回复,经过几天我得到了解决方案,请看下面的答案。

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


【解决方案1】:

我已经解决了这个问题!!!!!!!!!在您的 PHP 代码中,您不需要包含“registration_ids”来发送下游消息,“registration_ids”用于为多个注册令牌创建设备组,而不是向您的应用程序发送下游消息。

除了从你的 PHP 服务器发送一条下游消息,你可以尝试使用 curl 在你的终端发送一个推送通知(你还需要确保你的应用程序在后台但没有终止):

curl -i -H "Content-Type:application/json" -H "授权:key=API_KEY" -X POST -d '{"to":"REGISTRATION_TOKEN", “通知”:{“声音”:“默认”,“徽章”:“1”,“标题”:“默认”, "body":"test",},"content_available":true}' https://android.googleapis.com/gcm/send

 if you are testing in development mode for ios:

_registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken, kGGLInstanceIDAPNSServerTypeSandboxOption:@YES};

在 ios 和 php 中使用此代码,您也可以在后台收到通知。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,我发现设置“优先级”键可以解决 APN 的问题并立即推送消息。

    根据此处的文档在您的负载中设置优先级键:https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message

    在这里,您可以在此处了解有关 Apple APN 优先级及其行为的更多信息: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html

    因此,要立即接收推送,请尝试以下有效负载示例:

    {
      "to": "gcm_device_token",
      "priority": "high",
      "content_available": false,
      "notification": {
        "sound": "default",
        "badge": "1",
        "title": "Push Title",
        "body": "Push Body"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-29
      • 2016-12-29
      • 1970-01-01
      • 2019-06-22
      • 2016-01-16
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      相关资源
      最近更新 更多