php - 从 APNS-php 错误中检索 token

标签 php iphone apple-push-notifications

我正在尝试实现 APNS-PHP,并发现在我的测试环境中有一些无效 token (随着测试设备移至生产环境)。

我需要从数组中的序列化对象获取 token ID,因为我想捕获这种情况并从数据库中删除无效 token 。我使用以下代码,但这不起作用:

    $aErrorQueue = $push->getErrors();
    if (!empty($aErrorQueue)) {
        foreach($aErrorQueue as $error){            
            foreach($error['ERRORS'] as $err){
                $message .=  $err['statusMessage'] . " ";
                if($err['statusCode'] == 8){
                    $phones = Phone::getPhonesWithToken($error['MESSAGE']['_aDeviceTokens:protected'][0]);
                    Phone::setToken($phones[0]['id'], "");      
                }
            }   
        }
    }

问题是 APNS_Message 是 $error['MESSAGE'] 中的序列化对象,我不记得如何访问该对象中的 token ...

变量转储:

["MESSAGE"]=> object(ApnsPHP_Message)#9 (8) { ["_bAutoAdjustLongPayload:protected"]=> bool(true) ["_aDeviceTokens:protected"]=> array(1) { [0]=> string(64) "018E4B9CB8CF73341CE4EBE7138E25E605CD80FB74B3A9701CE5CCA6D9363F3A" } ["_sText:protected"]=> NULL ["_nBadge:protected"]=> int(256) ["_sSound:protected"]=> NULL ["_aCustomProperties:protected"]=> NULL ["_nExpiryValue:protected"]=> int(604800) ["_mCustomIdentifier:protected"]=> string(17) "Message-Badge-004" }

最佳答案

_aDeviceTokens 是一个 protected 属性,你会发现直接访问这个属性会抛出异常。

您应该改为使用 Message 对象上的 getRecipients()getRecipient($recipientNumber = 0) 方法来检索设备 token (s).

例如:

$token = $error['MESSAGE']->getRecipient();

关于php - 从 APNS-php 错误中检索 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5537619/

相关文章:

php - html 表单输入 DOM 引用的意外输出

iphone - 旧项目在 iOS 5 上运行缓慢

ios - 缺少 APNs 证书。在设置中上传证书

.net - APN 失败并显示 "Authentication failed because the remote party has closed the transport stream"

iphone - Apple 推送通知注册和设备 token 收到说明?

php - 如何在大量数据中preg_replace_all

php - 处理admin系统用户和前端网站用户时如何处理用户权限?

javascript - 通过Modal显示汇总表单

iphone - 即使单击更新按钮后,分发配置文件仍然过期

ios - iMessage 贴纸在模拟器之外无法使用