1

私はトークン内部のデバイスを取得 - (BOOL)アプリケーションを:didFinishLaunchingWithOptions:

- (BOOL)application:didFinishLaunchingWithOptions: 

内のデバイストークン(APN)を取得する方法がわからない、私は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]; 
} 

おかげで任意の助けのためにたくさん:

は、ここに私のサンプルコードです。

答えて

2

application:didRegisterForRemoteNotificationsWithDeviceToken:は、現在のデバイストークンを取得する唯一のチャンスです。ただし、結果をNSUserDefaultsに保存して、そこから読み取ることができます。ほとんどの場合、アプリがアンインストール/再インストールされていない場合、起動時にデバイストークンは変わりません。

+0

良いアイデアwarrenm。 tx – dejoong

関連する問題