延迟推送通知并检查用户是否启用它 [英] Delayed push notifications and checking if user enabled it
问题描述
我开发了一个应用程序,它围绕推送通知构建自己.应用程序仅在用户达到注册过程的特定点时才请求通知权限.我已经设法做到以下几点:
- 该应用维护一个
NSUserDefaults
变量,该变量指示是否需要在启动时注册推送(默认情况下:不需要) - 当注册达到那个点时,我翻转变量并在 iOS 7 上调用
-registerForRemoteNotificationTypes:
和在 iOS 8 上调用-registerUserNotificationSettings:
除非用户已经启用推送通知,然后稍后在设置"中禁用它们,否则这可以正常工作.在这种情况下,我尝试在启动时重新注册推送,它既不调用 -application:didRegisterForRemoteNotificationsWithDeviceToken
也不调用 -application:didFailToRegisterForRemoteNotificationsWithError
.
附加信息,iOS 8 的 -isRegisteredForRemoteNotifications
也返回 YES
.(我没有测试但假设 -enabledNotificationTypes
可以在 iOS 7 上运行.)
如何检测这种情况并向用户显示请求者,要求他在设置"中重新启用通知?
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
<块引用>
返回一个布尔值,指示应用程序当前是否已注册用于远程通知.
声明 SWIFT func isRegisteredForRemoteNotifications() -> Bool目标-C- (BOOL)isRegisteredForRemoteNotifications 返回值 YES 如果应用程序已注册远程通知并收到其设备令牌如果注册未发生、失败或被拒绝,则为 NO由用户.
讨论 此方法仅反映成功完成当您调用registerForRemoteNotifications 方法.这个方法不反映由于连接性,推送通知是否实际可用问题.该方法返回的值考虑了用户接收推送通知的偏好.
适用于 iOS 8.0 及更高版本.
我会向 Apple 提交错误报告.
I develop an app, which builds itself around push notifications. The app requests notification permissions only when the user reaches certain point of the registration process. I have already managed to do the following:
- the app maintains an
NSUserDefaults
variable, which indicates if it is required to register for push at launch or not (by default: not) - when the registration reaches that point, I flip the variable and call
-registerForRemoteNotificationTypes:
on iOS 7 and-registerUserNotificationSettings:
on iOS 8
This works fine unless the user has already enabled push notifications and then disabled them later in the Settings. In this case I try to reregister Push at launch, which does not call either -application:didRegisterForRemoteNotificationsWithDeviceToken
nor -application:didFailToRegisterForRemoteNotificationsWithError
.
Additional information, that iOS 8's -isRegisteredForRemoteNotifications
also returns YES
. (I did not test but suppose that -enabledNotificationTypes
works upto iOS 7.)
How can I detect this scenario and present the user a requester which asks him to reenable notifications in the Settings?
[[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.
I would file a bug report at Apple.
这篇关于延迟推送通知并检查用户是否启用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!