gpt4 book ai didi

ios - 删除应用程序后获取推送通知的设备 token

转载 作者:可可西里 更新时间:2023-11-01 03:03:52 26 4
gpt4 key购买 nike

当您第一次安装应用程序并想要注册推送通知时,该应用程序会询问您是否要接收提醒。这将永久保存在设置中,即使在删除应用程序后也是如此。

基本上,为了保存 token ,我们这样做:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *token = [[[deviceToken description]
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
stringByReplacingOccurrencesOfString:@" " withString:@""];
[[NSUserDefaults standardUserDefaults] setValue:token forKey:kDeviceTokenKey];
}

但问题是,当应用程序从设备中删除时,NSUserDefaults 会被删除,但推送设置不会。所以它不会再询问,因此不会再调用委托(delegate)方法,因此我没有 token 了,但推送仍然激活。

在描述的场景中是否有机会取回 token ?

最佳答案

来自 Push Notification Programming Guide

An application should register every time it launches and give its provider the current token. It calls the registerForRemoteNotificationTypes: method to kick off the registration process.

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. If a user restores a backup to a device or computer other than the one that the backup was created for (for example, the user migrates data to a new device or computer), he or she must launch the application at least once for it to receive notifications again. If the user restores backup data to a new device or computer, or reinstalls the operating system, the device token changes. Moreover, never cache a device token and give that to your provider; always get the token from the system whenever you need it. 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.

回答您的问题:在每次启动时调用 registerForRemoteNotificationTypes:,并使用最新的 token 。

关于ios - 删除应用程序后获取推送通知的设备 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16982216/

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