Getting token from APNS-php error

I am trying to implement APNS-PHP and found that in my test environment I have several invalid tokens (since the test devices switched to production).

I need to get the token identifier from a serialized object in an array, since I want to catch this script and remove invalid tokens from the database. I am using the following code, but this does not work:

$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'], ""); } } } } 

The problem is that APNS_Message is a serialized object in $ error ['MESSAGE'], and I don’t remember how to access the token in this object ...

Reset Var:

["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 :ULL" protected =]>> =)> =) ["_nExpiryValue: protected"] => Int (604800) ["_mCustomIdentifier: protected"] => string (17) "Message-Badge-004"}

+4
source share
2 answers

$error['MESSAGE']->_aDeviceTokens[0]

0
source

_aDeviceTokens is a protected property, you will find that access to this property will directly throw an exception.

Instead, you should use the getRecipients() or getRecipient($recipientNumber = 0) method of the Message object to retrieve the device tokens (s).

For instance:

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

Source: https://habr.com/ru/post/1346543/


All Articles