Can push messages distinguish between two types of prohibit notification and uninstallation?

Source: Internet
Author: User
The message pushes iOS with apns,android with GCM. Push failure will return invalid tokens, but in invalid Tokne, can you tell which ones are forbidden and which are caused by uninstalling the app?

1 APNS PHP push-back error handling
push.php

if (!empty ($aMessage [' ERRORS '])) {foreach ($aMessage [' ERRORS '] as $aError) {if ($aError [' statusCode '] = = 0) {$this->_ Log ("Info:message ID {$k} {$sCustomIdentifier} has no error ({$aError [' StatusCode ']}), removing from queue ..."); $this-&G T;_removemessagefromqueue ($k); Continue 2;} else if ($aError [' StatusCode '] > 1 && $aError [' StatusCode '] <= 8) {$this->_log ("Warning:message ID {$k} {$sCustomIdentifier} has a unrecoverable error ({$aError [' StatusCode ']}), removing from queue without retrying ... "); This->_removemessagefromqueue ($k, True); Continue 2;}} if ($nErrors = count ($aMessage [' ERRORS ']) >= $this->_nsendretrytimes) {$this->_log ("Warning:message ID {$k} {$sCustomIdentifier} have {$nErrors} errors, removing from queue ... "); $this->_removemessagefromqueue ($k, true); Continue;}}

By prohibiting notification, APNs will not give an error and will not use this token as an invalid or incorrect token.

Uninstall app, will call to the following judgment, StatusCode equals 8

if ($aError [' StatusCode '] > 1 && $aError [' StatusCode '] <= 8) {$this->_log ("Warning:message ID {$k} {$sCu Stomidentifier} has a unrecoverable error ({$aError [' StatusCode '}), removing from queue without retrying ... "); $this-& Gt;_removemessagefromqueue ($k, True); Continue 2;}

Therefore, the APNS should be able to differentiate the push failures caused by the uninstallation, but the disable notification will not respond

2 GCM Error-Judging code analysis:
Response.class.php

/** * Returns An array containing invalid registration IDs * They must is removed from DB because the application     was uninstalled from the device.  * * @return Array */Public function getinvalidregistrationids () {if ($this->getfailurecount () = =        0) {return array (); } $filteredResults = Array_filter ($this->results, function ($result) {return (Isset ($r esult[' ERROR ']) && (($result [' error '] = = "notregistered") | |            ($result [' error '] = = "Invalidregistration")));        });    Return Array_keys ($filteredResults); }/** * Returns an array of registration IDs for which you must resend a message (?), * cause devices aren ' t av     Ailable now. * * @TODO: Check if it be auto sended later * * @return array */Public function Getunavailableregistra        Tionids () {if ($this->getfailurecount () = = 0) {return array ();    }    $filteredResults = Array_filter ($this->results, function ($result) {return (                    Isset ($result [' Error ']) && ($result [' error '] = = "Unavailable")            );        });    Return Array_keys ($filteredResults); }

If notification is forbidden, none of the above 2 methods will write the wrong token, which means that the token is valid and does not return an error.
If you uninstall the app, it will be executed to Getinvalidregistrationids, and $result[' error ']==notregistered

In this way, if GCM returns notregistered, it is the error message that the uninstallation generates, and the non-notification, GCM is sent as normal token.


Through the above test, it is explained that APNs and GCM are treated as normal tokens for the forbidden Notice, and the uninstall app will be considered as invalid token. (A new token will be generated when reloading after unloading)

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.