Can push messages distinguish between disabling notifications and uninstalling?

The message push ios uses apns, and android uses gcm. If the push fails, an invalid token will be returned, but among the invalid tokens, can you distinguish which ones are forbidden notifications and which ones are caused by uninstalling the app?

1 APNS PHP push returns 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->_removeMessageFromQueue($k);
							continue 2;
						} else if ($aError['statusCode'] > 1 && $aError['statusCode'] <= 8) {
							$this->_log("WARNING: Message ID {$k} {$sCustomIdentifier} has an 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} has {$nErrors} errors, removing from queue..."
						);
						$this->_removeMessageFromQueue($k, true);
						continue;
					}
				}


By disabling the notification, apns will not report an error and will not treat the token as an invalid or wrong token.

Uninstalling the app will call the following judgment, statusCode is equal to 8
if ($aError['statusCode'] > 1 && $aError['statusCode'] <= 8) {
							$this->_log("WARNING: Message ID {$k} {$sCustomIdentifier} has an unrecoverable error ({$aError['statusCode']}), removing from queue without retrying...");
							$this->_removeMessageFromQueue($k, true);
							continue 2;
						}


Therefore, apns should be able to distinguish the push failure caused by uninstallation, but disabling notification cannot reflect

the error judgment code analysis of 2 GCM:
Response.class.php

/**
     * Returns an array containing invalid registration ids
     * They must be 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($result['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 available now.
     *
     * @TODO: check if it be auto sended later
     *
     * @return array
     */
    public function getUnavailableRegistrationIds()
    {
        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 disabled, neither of the above two methods will write an error token, which means that notification is disabled, the token is also valid, and no error will be returned.
If the app is uninstalled, getInvalidRegistrationIds will be executed, and $result['error']==NotRegistered

. If GCM returns NotRegistered, it means that the error message generated by the uninstallation is an error message, and notification is prohibited. GCM sends it as a normal token. out.


Through the above tests, it shows that apns and gcm treat the prohibition notification as a normal token, and uninstalling the app will treat it as an invalid token. (If you uninstall and reinstall, a new token will be generated)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486130&siteId=291194637
Recommended