gpt4 book ai didi

ios - 第二次获取ios push deviceToken

转载 作者:行者123 更新时间:2023-11-29 12:34:05 25 4
gpt4 key购买 nike

我需要获取 deviceToken。当我向我的应用程序添加推送通知时,我通过 didRegisterForRemoteNotificationsWithDeviceToken

收到了 deviceToken

但现在我需要重新获取它,但我没有保存。didRegisterForRemoteNotificationsWithDeviceToken 只调用一次,其他时候应用只运行 registerUserNotificationSettings

我想将所有新用户的 token 保存到 [NSUserDefaults standardUserDefaults] 但它只适用于新用户。如何处理当前用户?

最佳答案

在“didFinishLaunchingWithOptions”方法中添加以下代码……

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}

然后“didRegisterForRemoteNotificationsWithDeviceToken”方法将在应用程序启动期间的每次调用“didFinishLaunchingWithOptions”时被调用。

关于ios - 第二次获取ios push deviceToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26835452/

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