Wie man Device-Token in didFinishLaunchingWithOptions

Ich rufe device-token in meiner ersten viewcontroller. Und kann ich nicht bekommen, weil Device-token ist null. Hier unten ist mein code in appdelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];

    return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    token = [[deviceToken description] stringByTrimmingCharactersInSet:      [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"Device Token ---%@", token);
    [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"DeviceToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

Wenn ich rufe in Viewcontroller :

NSString *token=  [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"];

token ist null.

  • versuchen Sie es am simulator?
  • Versuchen Sie es mit dem echten Gerät.
  • Überprüfen Sie Ihre provisioning-Profilen und bauen im realen Gerät.
InformationsquelleAutor santa | 2013-09-13
Schreibe einen Kommentar