Google Cloud Messaging registration id expiration

后端 未结 4 722
野性不改
野性不改 2020-12-30 10:53

I am using Google Cloud Messaging for my Android application and I am trying to understand when the registration id expires. From this post I was able to understand that Goo

4条回答
  •  一向
    一向 (楼主)
    2020-12-30 11:22

    To obtain the latest GCM ID Here is my work around.

    $result = curl_exec($ch);
    $result = json_decode($result, true);
    $GCMIDChanged = $result['canonical_ids'];
    if($GCMIDChanged)
    {
        $NewGCMId = $result['results'][0]['registration_id'];
        //Update your DB with $NewGCMId
    }
    

    In the above code, I am checking whether the canonical_ids exists in the result.

    If the canonical_ids exists then i am getting the new registration_id

    So, Now the system will update automatically the New Gcm Id whenever it is changed.

    Update :

    The below code can be used if the GCM Id is changed multiple times

    $GCMIDChanged = $result['canonical_ids'];
    if($GCMIDChanged)
    {
        $NewGCMIdList = end($result['results']);
        $NewGCMId =  $NewGCMIdList['registration_id'];
    }
    

提交回复
热议问题