【问题标题】:APNS rejects notification with reason "DeviceTokenNotForTopic"APNS 以“DeviceTokenNotForTopic”为由拒绝通知
【发布时间】:2020-03-31 13:44:40
【问题描述】:

我仅在尝试使用 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];

自 Xcode 11 和 iOS13 以来,PushKit 发生了更改以支持 CallKit,因此我尝试改用 UserNotifications,如 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.

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

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

并接收令牌:

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

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

【问题讨论】:

    标签: ios objective-c apple-push-notifications pushkit usernotifications


    【解决方案1】:

    对于我来说,我已经更改了应用程序的名称和捆绑 ID,并且我没有更新设备令牌和带有图像通知的证书。

    为了解决这个问题,我首先访问了我的 Apple Developer 帐户的 Certificates, Identifiers & Profiles 部分,并生成了一个具有 AppGroups 功能的新证书。

    然后我在AppDelegate的函数调用中得到了一个新的设备令牌

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

    在从deviceToken参数中获取令牌并使用它发送通知后,它又开始工作了。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2011-09-28
        • 2015-12-24
        • 1970-01-01
        • 2012-12-29
        • 1970-01-01
        • 2015-09-16
        • 2014-02-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多