gcm push notification: first success, then not registered in IOS

前端 未结 3 1362
暗喜
暗喜 2021-01-15 10:57

After all passages for receive the notification with google cloud messaging in IOS but i have this problem: i send the post in php for the notification with server key and d

3条回答
  •  有刺的猬
    2021-01-15 11:43

    Some week ago, we also got NotRegistered error on second message send attempt. But For my experience, problem is not on ios side. The problem is on sent message parameters.

    Please try to send all required and optional parameters. Maybe you want to give a try to PHP script on this Q&A

    Tip: Sending parameter "content_available as true, priority as high and notification as data" may help.

    Below Example Json received with success again and again by ios devices.

    "Content-Type" is "application/json"
    
    {
        "registration_ids":[
        "",
        "",
        ],
        "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"
        }
     }
    

    Edit 2: Give a try that;

     $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;
    

提交回复
热议问题