APNS rejects notification with reason "DeviceTokenNotForTopic"
Asked Answered
I

3

11

I'm receiving this error only when trying to register for remote notifications using UserNotifications framework. When using PushKit everything works ok.

    dispatch_queue_t mainQueue = dispatch_get_main_queue();
    // Create a push registry object
    self.voipRegistry = [[PKPushRegistry alloc] initWithQueue: mainQueue];
    // Set the registry's delegate to self
    self.voipRegistry.delegate = self;
    // Set the push type to VoIP
    self.voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];

Since Xcode 11 and iOS13 there are changes in PushKit to support CallKit, so I'm trying to use UserNotifications instead, as described in Apple's documentation

Important
If you are unable to support CallKit in your app, you cannot use PushKit to handle push notifications. Instead, configure your app's push notification support with the UserNotifications framework.

I'm registering for remote notifications this way

- (BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
    [[UIApplication sharedApplication] registerForRemoteNotifications];

And receiving token:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

But when I'm sending notification from my server, I get DeviceTokenNotForTopic. I'm not sure, if UserNotifications framework uses different APNs server or token format is different.

Invention answered 6/12, 2019 at 14:42 Comment(0)
V
15

APNS sends such error if bundleID of your app different from the apns-topic that you are sending from the server in request for voip push. Or a certificate for a voip push is generated for another bundleID.

Error code https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html More discussions here. https://github.com/QuickBlox/quickblox-ios-sdk/issues/1020

Verso answered 23/3, 2020 at 15:25 Comment(0)
F
5

For me, I had changed the app's name and bundle ID and I hadn't renewed the device token and the certificate for notifications with images.

To solve that, I firstly went to the Certificates, Identifiers & Profiles section of my Apple Developer account and generated a new certificate with the AppGroups Capability.

Then I got a new device token in the calling of the AppDelegate's function

application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)

After getting the token from the deviceToken parameter and using it for sending the notification, it started working again.

Fi answered 4/11, 2020 at 10:47 Comment(0)
T
-8

if u r facing devicetokennotfortopic then just try this

topic should be your bundle id of u r application i fixed my issue

ex this is u r bundle id com.app.xxx.SumNotService

i have removed SumNotService

com.app.xxx(this worked for me)

try

Turves answered 21/7, 2022 at 6:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.