APNS 以“DeviceTokenNotForTopic”为由拒绝通知

Rus*_*lan 5 objective-c apple-push-notifications ios pushkit usernotifications

我仅在尝试使用 UserNotifications 框架注册远程通知时收到此错误。使用 PushKit 时一切正常。

    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];
Run Code Online (Sandbox Code Playgroud)

从 Xcode 11 和 iOS13 开始,PushKit 发生了变化以支持 CallKit,因此我尝试使用 UserNotifications 代替,如Apple 文档中所述

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.
Run Code Online (Sandbox Code Playgroud)

我正在以这种方式注册远程通知

- (BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
    [[UIApplication sharedApplication] registerForRemoteNotifications];
Run Code Online (Sandbox Code Playgroud)

并接收令牌:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
Run Code Online (Sandbox Code Playgroud)

但是当我从我的服务器发送通知时,我收到 DeviceTokenNotForTopic。我不确定,如果 UserNotifications 框架使用不同的 APNs 服务器或令牌格式不同。

小智 10

如果您的应用程序的 bundleID 与您apns-topic在请求 voip 推送时从服务器发送的bundleID 不同,则 APNS 会发送此类错误。或者为另一个 bundleID 生成一个用于 voip 推送的证书。

错误代码https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html 更多讨论在这里。https://github.com/QuickBlox/quickblox-ios-sdk/issues/1020