什么时候调用 didRegisterForRemoteNotificationsWithDeviceToken? [英] When is didRegisterForRemoteNotificationsWithDeviceToken called?

查看:94
本文介绍了什么时候调用 didRegisterForRemoteNotificationsWithDeviceToken?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多关于 didRegisterForRemoteNotificationsWithDeviceToken 的问题,但他们都回避了一个非常直接的问题,我似乎找不到确切的答案.

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.

对于以所有其他方式正确设置通知并具有适当网络连接的应用程序:什么时候调用 didRegisterForRemoteNotificationsWithDeviceToken?一些可能的选择可能是:

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:

  1. 每次应用启动时
  2. 仅在初始提示用户接受推送通知后
  3. 还有别的吗?

推荐答案

在你的UIApplication中调用该方法后,应用委托会在远程通知注册成功后调用该方法:

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

(void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types

根据:http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html

当您发送此消息时,设备会启动 Apple Push Service 的注册过程.如果成功,应用程序委托会在 application:didRegisterForRemoteNotificationsWithDeviceToken: 方法中收到一个设备令牌;如果注册不成功,则通过 application:didFailToRegisterForRemoteNotificationsWithError: 方法通知委托人.如果应用程序委托收到设备令牌,它应该与其提供者连接并将令牌传递给它.

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.

现在,进一步详细说明,通常应用程序会在您的应用程序委托中的 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中调用 registerForRemoteNotificationTypes.因此,application:didRegisterForRemoteNotificationsWithDeviceToken 通常会在应用程序启动后立即调用.

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.

application:didRegisterForRemoteNotificationsWithDeviceToken 在第一次之后仍然会被调用以进行后续注册.

The application:didRegisterForRemoteNotificationsWithDeviceToken still gets called for subsequents registration after the first.

这篇关于什么时候调用 didRegisterForRemoteNotificationsWithDeviceToken?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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