推送通知设备令牌?

时间:2009-08-27 10:56:49

标签: iphone objective-c ios token apple-push-notifications

如何从我的iPhone设备获取设备令牌?

3 个答案:

答案 0 :(得分:14)

此方法将在调试模式下在控制台中打印deviceToken,如果您想查看UIAlert中也可以看到的设备令牌。

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"APN device token: %@", deviceToken);
    NSString *deviceTokenString = [NSString stringWithFormat:@"%@",deviceToken];
    UIAlertView *deviceTokenAlert = [[UIAlertView alloc] initWithTitle:@"Device Token"
                                                            message:deviceTokenString
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];

}

答案 1 :(得分:7)

如果您已实施此方法

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

}

对于推送通知,您将获得设备令牌(此方法实际上是您在应用程序中实现的两种方法之一)

这可能会发现它很有用http://urbanairship.com/docs/push.html

您还可以查看Push Notification in Iphone application

我希望你觉得这很有用。

答案 2 :(得分:6)

此方法将在控制台中显示您的设备令牌。

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

    NSString *str = [NSString 
                     stringWithFormat:@"%@",deviceToken];
    NSString *newString = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
    newString = [newString stringByReplacingOccurrencesOfString:@"<" withString:@""];
    newString = [newString stringByReplacingOccurrencesOfString:@">" withString:@""];


    [[NSUserDefaults standardUserDefaults] setObject:newString forKey:@"deviceToken"];



    NSLog(@"Your deviceToken ---> %@",newString);

}