内部にデバイストークン(APN)を取得する方法がわかりません
- (BOOL)application:didFinishLaunchingWithOptions:
AppDelegateでデバイストークンを取得できる唯一の場所は
- (void)application:didRegisterForRemoteNotificationsWithDeviceToken:
ここで、application:didRegisterForRemoteNotificationsWithDeviceTokenは、非同期で実行されるか、didFinishLaunchingWithOptionsの後に実行されます。それで、didFinishLaunchingWithOptionsでデバイストークンを取得する方法はありますか?didFinishLaunchingWithOptionsからプッシュしたViewControllerに渡したいからです。
これが私のサンプルコードです:
- (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];
}
助けてくれてありがとう。