gpt4 book ai didi

iOS DeviceToken : How to pass deviceToken from AppDelegate to ViewController?

转载 作者:行者123 更新时间:2023-11-29 10:37:13 24 4
gpt4 key购买 nike

我遇到了一些奇怪的问题。实际上 viewController 的 ViewDidLoad 方法在 AppDelegate 的 didRegisterForRemoteNotificationsWithDeviceToken 方法之前调用

AppDelegate中的代码如下

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);

NSString* newToken = [deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"token:%@",newToken);
NSUserDefaults *defaultValues = [NSUserDefaults standardUserDefaults];
[defaultValues setValue:newToken forKey:key_device_token];
[defaultValues synchronize];
}

ViewDidLoad方法代码

- (void)viewDidLoad
{
[super viewDidLoad];


NSLog(@"ABCD");
}

控制台输出如下

2

014-10-10 16:59:15.590 FollowMe[650:60b] ABCD
2014-10-10 16:59:15.592 FollowMe[650:60b] app dir: file:///var/mobile/Applications/94B3DF5E-B0CB-4F0B-99E7-2DFEBDC30ECB/Documents/
2014-10-10 16:59:15.693 FollowMe[650:60b] My token is: <3fff5f77 d15d7680 f8028b92 d1ebaf9b 06457115 336f1ee5 56172de6 5d8217c5>
2014-10-10 16:59:15.695 FollowMe[650:60b] token:3fff5f77d15d7680f8028b92d1ebaf9b06457115336f1ee556172de65d8217c5

谁能告诉我我的代码有什么问题?

最佳答案

没什么,您为“推送通知”注册了您的应用程序,并等待来自“Apple”的 token 。当您收到它是正常的,您的应用首先创建您的 viewcontroller

在方法中:

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

通知您 viewcontroller 关于 token 。您有多种选择,找出最适合您的应用架构的选项。

如果您需要更多详细信息,请参阅有关 APNS 的精彩教程: http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

关于iOS DeviceToken : How to pass deviceToken from AppDelegate to ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26298401/

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