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

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

问题描述

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

当用户第一次安装应用并提示是否接受通知时,如果用户接受,是否会调用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吗?或者我们必须调用registerForRemoteNotificationTypes 在 AppDelegate 中?但是,代表会在未来的发布中被调用两次吗?

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.

推荐答案

如果用户接受初始提示,会自动调用 didRegisterForRemoteNotificationsWithDeviceToken 吗?不,您的远程通知注册过程在单击允许访问"时开始,但仅在成功注册 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天全站免登陆