I don't know how to get device token (APN) inside
- (BOOL)application:didFinishLaunchingWithOptions:
the only place I can get the device token in AppDelegate is in
- (void)application:didRegisterForRemoteNotificationsWithDeviceToken:
where application:didRegisterForRemoteNotificationsWithDeviceToken will run asynchronous or after didFinishLaunchingWithOptions. So, is there any way to get device token in didFinishLaunchingWithOptions?? Because I want to pass it into my ViewController that pushed from didFinishLaunchingWithOptions.
Here is my sample code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
for (id key in launchOptions) {
NSLog(@"Key: %@, Value %@", key, [launchOptions objectForKey: key]);
}
AddViewController *avc = [[AddViewController alloc] init];
avc.managedObjectContext = self.managedObjectContext;
avc.pushToken = self.pushToken;
UINavigationController *uinav = [[UINavigationController alloc] init ];
[uinav pushViewController:avc animated:YES];
[_window addSubview:uinav.view];
[avc release];
[self.window makeKeyAndVisible];
// Let the device know we want to receive push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
self.pushToken = [NSString stringWithFormat:@"%@", deviceToken];
}
Thanks a lot for any help.