APNS issue about devicetoken not for topic and bad device token in PHP

3.4k Views Asked by At

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.

0

There are 0 best solutions below