这是用来从php脚本发送消息到我的ios应用程序的代码:
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $devices,
'data' => array("message"=>"hi")
);
$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_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
这段代码是功能性的,但我希望能够发送推送通知,而不仅仅是消息。但是,当我像Google云消息传递文档中描述的那样包含通知有效负载时,不会调用方法application:didReceiveRemoteNotification:fetchCompletionHandler:
$fields = array(
'registration_ids' => $devices,
'content_available' => true ,
'notification' => array("title" => "title", "body"=>"body"),
'data' => array("message"=>"hi")
);
我有一个apns开发证书,我已经在委托中注册了我的应用程序的通知。我还成功地从谷歌获得了一个设备令牌。非常感谢您的帮助。谢谢!
您是否在Apple Watch上进行测试?根据这里https://developers.google.com/cloud-messaging/server-ref, notification
中的title
键仅在Watch中使用。
你应该尝试在你的notification
字典中只有一个body
键,然后看看它是否有效。