延迟推送通知和检查,如果用户启用了它 [英] Delayed push notifications and checking if user enabled it

查看:430
本文介绍了延迟推送通知和检查,如果用户启用了它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,它建立自己周围推送通知。该应用程序要求,只有当用户到达登记过程中的某些点通知的权限。我已经成功地做​​到以下几点:


  • 应用程序保持着一个 NSUserDefaults的变量,如果需要为推动在启动或没有(默认:没有)寄存器这表明

  • 报名时达到这一点,我翻转变量,并调用 -registerForRemoteNotificationTypes:在iOS 7和 -registerUserNotificationSettings:在iOS 8

除非用户已经启用了推送通知,然后在设置后关闭它们时,该工作正常。在这种情况下,我尝试重新注册在发射推送,这不叫任何 -Application:didRegisterForRemoteNotificationsWithDeviceToken 也不 -Application:didFailToRegisterForRemoteNotificationsWithError

其他信息,即8 iOS版的 -isRegisteredForRemoteNotifications 也返回。 (我没有测试,但假设 -enabledNotificationTypes 作品高达7 iOS版)。

我怎么可以检测到这种情况和present用户而要求他重新启用在设置通知的请求?


解决方案

  [UIApplication的sharedApplication] isRegisteredForRemoteNotifications]


  

返回一个布尔值指示应用程序是否当前注册
  远程通知。


  
  

宣言SWIFT FUNC isRegisteredForRemoteNotifications() - >布尔
  Objective-C的
   - (BOOL)isRegisteredForRemoteNotifications返回值是如果应用程序注册了远程通知,并收到了设备令牌
  或NO,如果没有发生注册,失败,或已被拒绝
  由用户。


  
  

讨论这个方法只反映的顺利完成
  远程注册过程中,当你调用开头
  registerForRemoteNotifications方法。此方法不会反映
  推送通知是否实际可用由于连接
  的问题。 此方法返回的值考虑了
  用户的preferences接收推送通知。


  
  

供货情况在IOS 8.0及更高版本。


<一个href=\"https://developer.apple.com/library/$p$prelease/iOS/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/isRegisteredForRemoteNotifications\">Link苹果Doc的

我在苹果公司提交的bug报告。

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.

Link to Apple Doc's

I would file a bug report at Apple.

这篇关于延迟推送通知和检查,如果用户启用了它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆