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

标签 ios objective-c ios8 push-notification apple-push-notifications

我开发了一个应用程序,它围绕推送通知构建自身。只有当用户到达注册过程的特定点时,该应用程序才会请求通知权限。我已经设法做到了以下几点:

  • 应用维护一个 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.

Link to Apple Doc's

我会向 Apple 提交错误报告。

关于ios - 延迟推送通知并检查用户是否启用了它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25017429/

相关文章:

ios - 如何从 KISSXML 中删除 xml 声明?

iOS 日历事件 View 表示

ios - 如何在 Objective-C 和 Swift 中实现 "didSelectButtonInCellAtIndexPath:"?

ios - 如何有条件地导入模块?

ios - 提示询问用户是否要继续让您的应用程序收集后台位置 - 这种情况多久发生一次?

ios - Simperium共享公用数据集

swift - IOS8 TableViewController Pull to Refresh 无法添加 Action

swift - 需要说明旋转 AV 摄像机的步骤

objective-c - NSDateFormatter stringFromDate 一直返回 nil

iOS EXC_BAD_ACCESS KERN_INVALID_ADDRESS