我正在努力让后台通知在带有 GCM 的 ios 上工作 - 非后台通知已经在工作。
在后台通知有时会来,有时不会。我用了
内容可用=真;
我也成功获得了注册 token 。
此代码功能
$fields = array(
'registration_ids' => $devices,
'content_available' => true ,
'notification' => array("title" => "title", "body"=>"body"),
'data' => array("message"=>"hi")
);
但不会在后台收到通知。你能告诉我当应用程序在后台时 GCM 在 Ios 中不工作的确切原因吗?
最佳答案
我已经解决了问题!!!!!!!!!!在您的 PHP 代码中,您不需要包含“registration_ids”来发送下游消息,“registration_ids”用于为多个注册 token 创 build 备组,而不是向您的应用程序发送下游消息。
除了从 PHP 服务器发送下游消息外,您还可以尝试使用 curl 在终端中发送推送通知(您还需要确保您的应用程序处于后台但未终止):
curl -i -H "Content-Type:application/json" -H "Authorization:key=API_KEY" -X POST -d '{"to":"REGISTRATION_TOKEN", "notificaiton":{"sound":"default", "badge":"1", "title": "default", "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 中的此代码,您也可以在后台收到通知。
关于php - IOS GCM 推送通知在后台不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32567867/