Delayed push notifications and checking if user enabled it

风格不统一 提交于 2019-12-09 16:26:40

问题


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?


回答1:


[[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

I would file a bug report at Apple.



来源:https://stackoverflow.com/questions/25017429/delayed-push-notifications-and-checking-if-user-enabled-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!