当didRegisterForRemoteNotificationsWithDeviceToken叫什么名字? [英] When is didRegisterForRemoteNotificationsWithDeviceToken called?
问题描述
有很多关于didRegisterForRemoteNotificationsWithDeviceToken问题,但他们都回避一个很直接的问题,我似乎无法找到一个确切的答案。
对于正确设置了通知,在其他方面并有适当的网络连接的应用程序:当didRegisterForRemoteNotificationsWithDeviceToken叫什么名字?一些可能的选择可能是:
- 每次应用程序启动
- 初始提示用户只有在接受推送通知
- 别的东西吗?
应用程序代表将呼吁的远程通知注册成功的方法,你在你的UIApplication调用此方法后:
(无效)registerForRemoteNotificationTypes:(UIRemoteNotificationType)类型
块引用>据:<一href=\"http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html\">http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html
当您发送该消息,该设备发起与苹果推送服务的登记程序。如果成功,应用程序委托接收在应用程序的设备令牌:didRegisterForRemoteNotificationsWithDeviceToken:方式; didFailToRegisterForRemoteNotificationsWithError:方法,如果注册不成功,委托通过的应用程序通知。如果应用程序代理接收设备令牌,它应该与它的供应商连接,并通过它的令牌。
块引用>现在,为了进一步阐述,通常一个应用程序将调用 registerForRemoteNotificationTypes 在 didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions 在应用程序委托。因此,在应用:didRegisterForRemoteNotificationsWithDeviceToken ,然后通常是启动该应用程序后调用的瞬间
编辑:应用程序:didRegisterForRemoteNotificationsWithDeviceToken仍然得到后的第一个要求subsequents登记
There are a lot of questions about didRegisterForRemoteNotificationsWithDeviceToken but they all sidestep a very direct question which I cannot seem to find an exact answer to.
For an app which is properly set up for notifications in all other ways and has proper network connectivity: when is didRegisterForRemoteNotificationsWithDeviceToken called? Some possible choices might be:
- Every time the app starts
- Only after the initial prompt to the user to accept push notifications
- Something else?
解决方案The application delegate will call the method upon successful registration of remote notification after you call this method in your UIApplication:
(void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
According to: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html
When you send this message, the device initiates the registration process with Apple Push Service. If it succeeds, the application delegate receives a device token in the application:didRegisterForRemoteNotificationsWithDeviceToken: method; if registration doesn’t succeed, the delegate is informed via the application:didFailToRegisterForRemoteNotificationsWithError: method. If the application delegate receives a device token, it should connect with its provider and pass it the token.
Now, to elaborate further, normally an app will call the registerForRemoteNotificationTypes in your didFinishLaunchingWithOptions:(NSDictionary *)launchOptions in your application delegate. And therefore, the application:didRegisterForRemoteNotificationsWithDeviceToken is then usually called moments after the launch of the application.
Edit: The application:didRegisterForRemoteNotificationsWithDeviceToken still gets called for subsequents registration after the first.
这篇关于当didRegisterForRemoteNotificationsWithDeviceToken叫什么名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!