ios – 延迟推送通知并检查用户是否启用了它

前端之家收集整理的这篇文章主要介绍了ios – 延迟推送通知并检查用户是否启用了它前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我开发了一个应用程序,它围绕推送通知构建.仅当用户到达注册过程的某个点时,应用才会请求通知权限.我已经设法做了以下事情:

>该应用程序维护一个NSUserDefaults变量,该变量指示是否需要在启动时注册推送(默认情况下:不是)
>当注册到达那一点时,我翻转变量并在iOS 7和-registerUserNotificationSettings上调用-registerForRemoteNotificationTypes:在iOS 8上

除非用户已启用推送通知,然后稍后在“设置”中禁用推送通知,否则此工作正常.在这种情况下,我尝试在启动时重新注册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.

Link to Apple Doc’s

我会向Apple提交一份错误报告.

原文链接:https://www.f2er.com/iOS/334031.html

猜你在找的iOS相关文章