我正在开发一些 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/