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

前端 未结 3 1363
暗喜
暗喜 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":[
        "<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"
        }
     }
    

    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;
    
    0 讨论(0)
  • 2021-01-15 11:47

    Op's own answer, removed from the edited question:

    The problem was the old account without the new provisioning profile, go to : XCode Accounts -> Apple IDs and view details -> Download All. For be sure go to : Targets -> project name -> Build Settings -> search "Provisioning Profile" -> change automatic and select your provisioning profile in use for certificates. The mystery is the xcode's reason don't warning me don't find the correct Provisioning Profile (different bundle id).

    0 讨论(0)
  • 2021-01-15 11:55

    My five cents In case you are having "notRegistered" error only when app is in production that was my mistake: I missed the that in the registration options provided in GCM:

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

    There is an option kGGLInstanceIDAPNSServerTypeSandboxOption which should be set to NO in case of production

    Hope it helps!

    0 讨论(0)
提交回复
热议问题