pushok
pushok copied to clipboard
DeviceTokenNotForTopic issue
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.
I got the same issues as you. Does any help please?
maybe you can try to set a push type with Payload setPushType method?
I'm also receiving the same thing when setting $payload->setPushType('voip')
. It appears to be VoIP push type related but I'm not sure what I'm missing? I see the same error, and the error description returned is
The device token does not match the specified topic
I'm also receiving the same thing when setting
$payload->setPushType('voip')
. It appears to be VoIP push type related but I'm not sure what I'm missing? I see the same error, and the error description returned isThe device token does not match the specified topic
Just to answer my own question, and hopefully help others, the problem was related to the device token. I was using rn firebase messaging().getAPNSToken()
which returns a standard push token.
The solution was to use https://github.com/react-native-webrtc/react-native-voip-push-notification to get a proper VoIP push token. After this our backend API was able to send the push notification successfully.
DeviceTokenNotForTopic
usually means the device token used is not related to the bundle id. In my case I had a typo in the bundle id.