我正面臨一些奇怪的問題。前AppDelegate中的didRegisterForRemoteNotificationsWithDeviceToken
方法其實叫ios DeviceToken:如何將deviceToken從AppDelegate傳遞給ViewController?
代碼在AppDelegate中的viewController的viewDidLoad方法如下
- (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");
}
的代碼下面是控制檯輸出
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
任何人都可以告訴我什麼是我的代碼的問題?