4

I am trying to integrate the sending of APNS for VOIP using this PHP Client library:

composer require edamov/pushok

I followed the steps on how to provide the right value in the $options array in which I cannot disclose here.

When I tried to dump the variables in the following code:

$options = [
    'key_id' => $keyid, // The Key ID obtained from Apple developer account
    'team_id' => $teamid, // The Team ID obtained from Apple developer account
    'app_bundle_id' => $bundleid, // The bundle ID for app obtained from Apple developer account
    'private_key_path' => $keyfile, // Path to private key
    'private_key_secret' => null // Private key secret
];

$authProvider = AuthProvider\Token::create($options);
$alert = Alert::create()->setTitle('Hello!');
$alert = $alert->setBody('First push notification');

$payload = Payload::create()->setAlert($alert);

//set notification sound to default
$payload->setSound('default');

$deviceTokens = [$token];

$notifications = [];
foreach ($deviceTokens as $deviceToken) {
    $notifications[] = new Notification($payload,$deviceToken);
}

$client = new \Pushok\Client($authProvider, $production = false);
$client->addNotifications($notifications);

$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)

var_dump($responses);

Here is what I'm getting:

array (size=1)
  0 => 
    object(Pushok\Response)[1564]
      private 'apnsId' => string '7EEEWAYS-BE3F-P0RK-J3RK-706FC55D5ABS' (length=36)
      private 'deviceToken' => string 'wlo83peah2f2ql686sfitzasro2wghri85x2l128t7gqysoba9jaezsve0y0nvpm' (length=64)
      private 'statusCode' => int 400
      private 'errorReason' => string 'DeviceTokenNotForTopic' (length=22)
      private 'error410Timestamp' => string '' (length=0)

I would like to ask or seek help on why I am getting the HTTP400 DeviceTokenNotForTopic error though I think the provided values in the $options array are correct?

Also, I just discovered that when I change the value of the second parameter of $client from this:

$client = new \Pushok\Client($authProvider, $production = false);
$client->addNotifications($notifications);

to this

$client = new \Pushok\Client($authProvider, $production = true);
$client->addNotifications($notifications);

I am getting the BadDeviceToken HTTP400 error:

array (size=1)
  0 => 
    object(Pushok\Response)[1564]
      private 'apnsId' => string '733TWAYS-S0UR-F1SH-CH0W-706FC55D5ABS' (length=36)
      private 'deviceToken' => string 'wlo83peah2f2ql686sfitzasro2wghri85x2l128t7gqysoba9jaezsve0y0nvpm' (length=64)
      private 'statusCode' => int 400
      private 'errorReason' => string 'BadDeviceToken' (length=14)
      private 'error410Timestamp' => string '' (length=0)

Thanks in advance.

bowmeow
  • 109
  • 1
  • 11
  • 3
    I'm not a PHP but an iOS developer and to me it sounds like the certificate you're providing is not associated with the "Topic" (aka your App bundle ID). When you created the APNS Key in the Apple Dev. Portal, are you sure that you selected the correct bundle identifier? Furthermore, make sure that you select the same environment **(Sandbox <-> Prod)** everywhere (Dev. Portal, PHP Code, Certificate...) - that has been an issue for me once. – emmics May 27 '20 at 08:04
  • Hello @mmika1000, I am going to ask my colleague about the details he gave to me. Thanks – bowmeow May 27 '20 at 08:22
  • Hello everyone, the environment that is being set in both API and the iOS app was set to development. We have two iOS mobile device, when we test the APNS (VoIP) in the first device, it works, while the second one return HTTP 400 `BadDeviceToken`. How is that possible that the other device is working while the other one is not? – bowmeow Jun 01 '20 at 09:20
  • Have the Apps been deployed the exact same way? And are you aware that DeviceToken change over time and you have to request them from APNS every time your App starts? Maybe also [this answer](https://stackoverflow.com/questions/42511476/what-are-the-possible-reasons-to-get-apns-responses-baddevicetoken-or-unregister) might be of help for you – emmics Jun 01 '20 at 21:06

0 Answers0