我开发了一个应用程序,它围绕推送通知构建自身。只有当用户到达注册过程的特定点时,该应用程序才会请求通知权限。我已经设法做到了以下几点:
- 应用维护一个
NSUserDefaults
变量,它指示是否需要在启动时注册推送(默认情况下:不需要) - 当注册达到那个点时,我翻转变量并在 iOS 7 上调用
-registerForRemoteNotificationTypes:
,在 iOS 8 上调用-registerUserNotificationSettings:
这工作正常,除非用户已经启用推送通知,然后稍后在“设置”中将其禁用。在这种情况下,我尝试在启动时重新注册 Push,它既不调用 -application:didRegisterForRemoteNotificationsWithDeviceToken
也不调用 -application:didFailToRegisterForRemoteNotificationsWithError
。
附加信息,iOS 8 的 -isRegisteredForRemoteNotifications
也返回 YES
。 (我没有测试,但假设 -enabledNotificationTypes
适用于 iOS 7。)
我如何检测这种情况并向用户显示请求者,要求他在“设置”中重新启用通知?
最佳答案
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
Returns a Boolean indicating whether the app is currently registered for remote notifications.
Declaration SWIFT func isRegisteredForRemoteNotifications() -> Bool OBJECTIVE-C - (BOOL)isRegisteredForRemoteNotifications Return Value YES if the app is registered for remote notifications and received its device token or NO if registration has not occurred, has failed, or has been denied by the user.
Discussion This method reflects only the successful completion of the remote registration process that begins when you call the registerForRemoteNotifications method. This method does not reflect whether push notifications are actually available due to connectivity issues. The value returned by this method takes into account the user’s preferences for receiving push notifications.
Availability Available in iOS 8.0 and later.
我会向 Apple 提交错误报告。
关于ios - 延迟推送通知并检查用户是否启用了它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25017429/