gcm推送通知:首先成功,然后不在IOS中注册

在所有的段落接收与谷歌云消息在IOS通知,但我有这个问题:我发送邮件在PHP的通知服务器密钥和设备的令牌,第一次的答复是“成功”,但没有收到任何设备,在第二次和随后的时间,响应是“未注册”。 我重复所有的段落:在钥匙串中创build新的钥匙,加载configuration文件,下载.cer,安装在钥匙串中,导出.p12,并在Google平台上插入证书“GoogleService-Info.plist”并重新加载设备的regId在PHP ,但答复总是这样。 请帮帮我。

这是我的PHP:

$apiKey = "server key"; $regId = 'registration token'; $url = 'https://gcm-http.googleapis.com/gcm/send'; $post = '{"to" : "' . $regId . '", "content_available" : true, "priority" : "high", "notification": {"title" : "test", "body" : "test"}}'; $headers = array( "Authorization:key=$apiKey", 'Content-Type:application/json' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); if ( curl_errno( $ch ) ) { echo 'GCM error: ' . curl_error( $ch ); } curl_close( $ch ); echo $result; 

Op自己的答案,从编辑的问题中删除:

问题是没有新的供应configuration文件的旧帐户,请转到:XCode帐户 – > Apple ID和查看详细信息 – >全部下载。 确保转到:目标 – >项目名称 – >生成设置 – >search“预configurationconfiguration文件” – >自动更改并select您的预configurationconfiguration文件用于证书。 神秘的是xcode的原因不警告我没有find正确的configuration文件(不同的捆绑ID)。

我的五美分如果你有“未注册”的错误,只有当应用程序在生产中是我的错误:我错过了在GCM提供的注册选项:

 [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:_gcmSenderID scope:kGGLInstanceIDScopeGCM options:_registrationOptions handler:self.registrationHandler]; 

有一个选项kGGLInstanceIDAPNSServerTypeSandboxOption生产的情况下应该设置为NO

希望能帮助到你!

一个星期前,我们还收到第二个消息发送尝试的NotRegistered错误。 但就我的经验来说,问题不在ios方面。 问题在于发送的消息参数。

请尝试发送所有必需和可选参数。 也许你想尝试在这个Q&A的 PHP脚本

提示:发送参数“content_available为true,优先级为高,通知为数据”可能有帮助。

下面的示例Json通过ios设备一次又一次地获得成功。

 "Content-Type" is "application/json" { "registration_ids":[ "<reg_id1>", "<reg_id2>", ], "priority":"high", "content_available":true, "time_to_live":2419200, "data":{ "message":"Test 15:46:49", "title":"" }, "notification":{ "title":"", "body":"Test 15:46:49", "sound":"default", "badge":"1" } } 

编辑2:尝试一下;

  $apiKey = "server key"; $regId = 'registration token'; $url = 'https://gcm-http.googleapis.com/gcm/send'; $post = '{"to" : "' . $regId . '","priority":"high","content_available":true,"time_to_live":2419200,"data":{"message":"GCM Notifier:Message Success","title":"GCM Notifier:Title Success"},"notification":{"title":"GCM Notifier:Title Success","body":"GCM Notifier:Message Success","sound":"default","badge":"1"}}'; $headers = array( "Authorization:key=$apiKey", 'Content-Type:application/json' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); if ( curl_errno( $ch ) ) { echo 'GCM error: ' . curl_error( $ch ); } curl_close( $ch ); echo $result;