我正面临着一些奇怪的问题。实际上,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有人能告诉我我的代码有什么问题吗?
发布于 2014-10-10 11:51:52
没什么,你注册你的应用程序“推送通知”,并等待来自“苹果”的令牌。当你收到它是正常的,你的应用程序首先创建你的viewcontroller。
在该方法中:
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken通知viewcontroller关于令牌的情况。你有多种选择,找出哪个更适合你的应用架构。
如果您需要更多的详细信息,请提供一个关于APNS:http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1的很好的教程。
发布于 2014-10-10 11:52:55
发布于 2014-10-10 11:47:01
在AppDelegate中设置一个委托方法,在完成didRegisterForRemoteNotificationsWithDeviceToken时调用该方法。将控制器附加到委托,因为在注册通知时会通知它。
https://stackoverflow.com/questions/26298401
复制相似问题