推送消息能不能区分禁止通知和卸载两种类型?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了推送消息能不能区分禁止通知和卸载两种类型?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2804字,纯文字阅读大概需要5分钟。
内容图文
![推送消息能不能区分禁止通知和卸载两种类型?](/upload/InfoBanner/zyjiaocheng/151/1d8def51cc5749b787819c0700993653.jpg)
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)
内容总结
以上是互联网集市为您收集整理的推送消息能不能区分禁止通知和卸载两种类型?全部内容,希望文章能够帮你解决推送消息能不能区分禁止通知和卸载两种类型?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。