我已經(jīng)在現(xiàn)有應用中配置了GCM,并且在那里收到了通知?,F(xiàn)在我面臨兩個問題:1)我退出應用程序時未收到通知,或者應用程序在后臺。2)我沒有在iPhone的通知區(qū)域中收到通知,僅當我的應用程序正在運行時,我才直接在該區(qū)域接收警報消息。當我下拉通知區(qū)域時,我在xcode的控制臺中收到此消息“無法連接到GCM:操作無法完成。(com.google.gcm錯誤2001。)”我的PHP文件在下面<?php// Payload data you want to send to iOSdevice(s)// (it will be accessible via intent extras) $data = array( 'message' => 'Hello World!');// The recipient registration tokens for this notification// http://developer.android.com/google/gcm/ $ids = array( 'kucy6xoUmx********eeRsla' );// Send a GCM pushsendGoogleCloudMessage( $data, $ids );function sendGoogleCloudMessage( $data, $ids ){ // Insert real GCM API key from Google APIs Console // https://code.google.com/apis/console/ $apiKey = 'AIz******9JA'; // Define URL to GCM endpoint $url = 'https://gcm-http.googleapis.com/gcm/send'; // Set GCM post variables (device IDs and push payload) $post = array( 'registration_ids' => $ids, 'data' => $data, ); // Set CURL request headers (authentication and type) $headers = array( 'Authorization: key=' . $apiKey, 'Content-Type: application/json' ); // Initialize curl handle $ch = curl_init(); // Set URL to GCM endpoint curl_setopt( $ch, CURLOPT_URL, $url ); // Set request method to POST curl_setopt( $ch, CURLOPT_POST, true ); // Set our custom headers curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); // Get the response back as string instead of printing it curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // Set JSON post data curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) ); // Actually send the push $result = curl_exec( $ch ); // Error handling if ( curl_errno( $ch ) ) { echo 'GCM error: ' . curl_error( $ch ); }?>
- 2 回答
- 0 關注
- 717 瀏覽
添加回答
舉報
0/150
提交
取消