gpt4 book ai didi

iphone - 如何在 didFinishLaunchingWithOptions 中获取 Device Token

转载 作者:行者123 更新时间:2023-11-28 18:21:55 26 4
gpt4 key购买 nike

我在我的第一个 viewcontroller 中调用设备 token 。而且我无法获得结果,因为设备 token 为空。以下是我在 appdelegate 中的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];

return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Device Token ---%@", token);
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"DeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

当我调用 Viewcontroller 时:

NSString *token=  [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"];

token 为空。

最佳答案

    NSString *device = [deviceToken description];
device = [device stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
device = [device stringByReplacingOccurrencesOfString:@" " withString:@""];

NSLog(@"My device is: %@", device);

这在我的设备上非常适合我。

关于iphone - 如何在 didFinishLaunchingWithOptions 中获取 Device Token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18785393/

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