gpt4 book ai didi

ios - didRegisterForRemoteNotificationsWithDeviceToken 调用了两次?

转载 作者:技术小花猫 更新时间:2023-10-29 10:37:11 36 4
gpt4 key购买 nike

有点类似于When is didRegisterForRemoteNotificationsWithDeviceToken called? .

当用户第一次安装应用时,提示是否接受通知,如果用户接受,是否会调用didRegisterForRemoteNotificationsWithDeviceToken

我目前在用户成功登录或创建帐户后调用 registerForRemoteNotificationTypes

在随后的启动中,即使没有在 AppDelegate 中调用 registerForRemoteNotificationTypes,也会调用 didRegisterForRemoteNotificationsWithDeviceToken 委托(delegate)。

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

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:...
}

但是通过在应用启动时请求 token ,委托(delegate)将被调用两次。

几个问题和需要澄清的问题:

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

  2. 如果用户接受初始提示,是否会自动调用didRegisterForRemoteNotificationsWithDeviceToken?或者我们必须调用AppDelegate 中的 registerForRemoteNotificationTypes?但是,代表将在未来的发布中被调用两次?

  3. 如果用户拒绝并稍后通过设置接受,会发生什么?

更新

0。要出现初始提示,必须调用 registerForRemoteNotificationTypes 才能显示提示?但是,如果我在 AppDelegate 中手动调用委托(delegate),委托(delegate)将被调用两次。应该是这样吗? 这不是真的。发现在 AppDelegate 中实际上有 2 个 registerForRemoteNotiicationTypes

最佳答案

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

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

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.

关于ios - didRegisterForRemoteNotificationsWithDeviceToken 调用了两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18589755/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com