didRegisterForRemoteNotificationsWithDeviceToken被调用了两次? [英] didRegisterForRemoteNotificationsWithDeviceToken called twice?

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

问题描述

有点类似于 RegisterForRemoteNotificationsWithDeviceToken什么时候被调用?.

当用户首先安装该应用并提示是否接受通知时,如果用户接受该通知,则会调用didRegisterForRemoteNotificationsWithDeviceToken吗?

When the user first installed the app and it prompts whether to accept notification, will didRegisterForRemoteNotificationsWithDeviceToken be called if the user accepts it?

在用户成功登录或创建帐户后,我当前正在呼叫registerForRemoteNotificationTypes.

I'm currently calling registerForRemoteNotificationTypes after the user successfully signs in or creates an account.

在随后的启动中,即使未在AppDelegate中调用registerForRemoteNotificationTypes,也会调用didRegisterForRemoteNotificationsWithDeviceToken委托.

In subsequently launches, the didRegisterForRemoteNotificationsWithDeviceToken delegate is called even without calling registerForRemoteNotificationTypes in AppDelegate.

如果我遵循文档和示例代码:

If I follow the docs and example code:

通过请求设备令牌,并在每次启动应用程序时将其传递给提供程序,可以帮助确保提供程序具有设备的当前令牌.

By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device.

- (void)applicationDidFinishLaunching:(UIApplication *)app {

   // other setup tasks here....
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:...
}

但是通过在应用启动时请求令牌,委托将被调用两次.

But by requesting the token when the app launches, the delegate will be called twice.

需要澄清几个问题:

  1. 要使初始提示出现,必须调用registerForRemoteNotificationTypes才能使提示出现?但是,如果我在AppDelegate中手动调用该委托,则该委托将被调用两次.应该是那样吗?

  1. For the initial prompt to happen, a call for registerForRemoteNotificationTypes must be made for the prompt to appear? But, the delegate will be called twice if I call this manually in AppDelegate. Is it suppose be that way?

如果用户接受初始提示,是否会自动调用didRegisterForRemoteNotificationsWithDeviceToken?还是我们必须调用 AppDelegate中的registerForRemoteNotificationTypes?但是随后,该代表将被召集两次以进行将来的发布吗?

If the user accepts the initial prompt, will didRegisterForRemoteNotificationsWithDeviceToken be called automatically? Or must we invoke registerForRemoteNotificationTypes in AppDelegate? But then the delegate will be called twice for future launches?

如果用户拒绝并随后通过设置"接受它,会发生什么情况?

If the user denies and later accept it via Setting, what happens?

更新

0.要使初始提示出现,必须调用registerForRemoteNotificationTypes才能使提示出现?但是,如果我在AppDelegate中手动调用该委托,则该委托将被调用两次. 这不是真的吗?发现实际上在AppDelegate中制作了2个registerForRemoteNotiicationTypes.

0. For the initial prompt to happen, a call for registerForRemoteNotificationTypes must be made for the prompt to appear? But, the delegate will be called twice if I call this manually in AppDelegate. Is it suppose be that way? This isn't true. Found out that there were actually 2 registerForRemoteNotiicationTypes being made in AppDelegate.

推荐答案

如果用户接受初始提示,是否会自动调用RegisterForRemoteNotificationsWithDeviceToken? 否,您的远程通知注册过程会在单击允许访问"后开始,但是只有成功注册APNS后才会调用didRegisterForRemoteNotificationsWithDeviceToken方法.

If the user accepts the initial prompt, will didRegisterForRemoteNotificationsWithDeviceToken be called automatically? No, Your remote notification registration process starts when 'allow access' is clicked, but didRegisterForRemoteNotificationsWithDeviceToken method is called only on successful APNS registration.

如果您的应用程序先前已注册,请致电 registerForRemoteNotificationTypes:操作系统中的结果 立即将设备令牌传递给委托人而不会产生 额外的开销

If your application has previously registered, calling registerForRemoteNotificationTypes: results in the operating system passing the device token to the delegate immediately without incurring additional overhead

您可以确定是否由于以下原因启动了应用程序 用户点击操作按钮或通知是否为 通过检查 应用程序状态.在代表的实施中 应用程序:didReceiveRemoteNotification:或 application:didReceiveLocalNotification:方法,获取 applicationState属性并对其进行评估.如果值为 UIApplicationStateInactive,用户点击操作按钮;如果 值是UIApplicationStateActive,应用程序位于以下位置时位于最前面 它收到了通知.

You can determine whether an application is launched as a result of the user tapping the action button or whether the notification was delivered to the already-running application by examining the application state. In the delegate’s implementation of the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification: method, get the value of the applicationState property and evaluate it. If the value is UIApplicationStateInactive, the user tapped the action button; if the value is UIApplicationStateActive, the application was frontmost when it received the notification.

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

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