ios - 在用户允许 iOS 上的通知之前调用的 APNS didRegisterForRemoteNotifications

标签 ios apple-push-notifications

我正在开发一些 iOS 应用程序,它们都属于同一个发布者,并且都启用了推送通知。当我调用 registerForRemoteNotificationTypes 时,我得到了允许或禁止推送通知的用户提示,但是我application:didRegisterForRemoteNotificationsWithDeviceToken: 之前被调用了 token 数据用户选择一个选项。当他们按下 OK 时,它会再次被调用。这正常吗?

另请注意:多个应用在同一台设备上运行时似乎会获得相同的 token 。

最佳答案

这是来自 Apple 文档。

When you send this message, the device initiates the registration process with Apple Push Service. If it succeeds, the application delegate receives a device token in the application:didRegisterForRemoteNotificationsWithDeviceToken: method; if registration doesn’t succeed, the delegate is informed via the application:didFailToRegisterForRemoteNotificationsWithError: method. If the application delegate receives a device token, it should connect with its provider and pass it the token.

The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.

我认为你所观察到的是正常的。没有提到 application:didRegisterForRemoteNotificationsWithDeviceToken 只有在用户授予权限时才会调用。我认为您可以通过在 NSUserDefaults 中缓存设备 token 来优化它,并在此方法中检查新 token 是否不等于缓存的 token 。

关于ios - 在用户允许 iOS 上的通知之前调用的 APNS didRegisterForRemoteNotifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15510190/

相关文章:

firebase - 我可以在 Firebase 上管理多少个客户端应用?

c++ - 从 Objective-C++ 调用 C++ 时出现 BAD_ACCESS 错误。所有文件都是 .mm 但仍然是这个问题

ios - 从应用商店安装后是否可以获取链接内容?

iphone - 比较两个图像是否相同(iOS)

ios - 将配置文件与 iOS 应用程序捆绑在一起

android - 是否可以从 GCM 以先进先出的顺序接收推送通知?

c# - PushSharp APNS 通知错误请求的功能不受支持

ios - 如何使用 CIQRCodeGenerator 生成中间带有 Logo 的二维码

ios - NSInvalidArgumentException isKindOfClass

ios - 推送通知不适用于 iOS9 及更高版本