1 apns php 的推送返回错误处理
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; } }
通过禁止通知,apns不会报错,不会将这个token当成无效或错误的token。
卸载app,会调用到以下判断,statuscode等于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; }
因此,apns应该是可以区分卸载导致的推送失败,但是禁止通知则无法反应
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); }
如果禁止通知,上述2个方法都不会写入错误token,也就是说禁止通知,token也是有效的,且不会返回错误。
如果是卸载app,则会执行到getinvalidregistrationids,且$result['error']==notregistered
这样,gcm如果返回的是notregistered,则说明是卸载产生的错误信息,而禁止通知,gcm是当成正常token发出去的。
通过以上测试,说明apns和gcm对禁止通知都是当成正常token来处理的,而卸载app则会当成无效的token。(卸载后重装的话,会生成新的token)