如何用UILabel显示APNS设备令牌?

时间:2012-06-06 13:23:20

标签: iphone objective-c uiviewcontroller uiresponder

我想用UILabel显示一个APNS设备令牌。

所以我在下面编码:

//AppDelegate.m

- (void)application:(UIApplication*)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
// TODO: Pass the token to our server
NSString *devToken = [[[[deviceToken description] 
                        stringByReplacingOccurrencesOfString:@"<"withString:@""] 
                       stringByReplacingOccurrencesOfString:@">" withString:@""] 
                      stringByReplacingOccurrencesOfString: @" " withString: @""];


NSString *str = [NSString 
                 stringWithFormat:@"Device Token=%@",devToken];
UIAlertView *alertCtr = [[UIAlertView alloc] initWithTitle:@"Token is " message:devToken delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
[alertCtr show];
NSLog(@"device token - %@",str);
viewc = [ViewController alloc];

viewc.tokenLabel.text = str;

}

但没有任何事情发生。怎么了?

1 个答案:

答案 0 :(得分:0)

viewc = [ViewController alloc];
viewc.tokenLabel.text = str;

alloc视图控制器之后,您应该init。并呈现它,无论是模态还是导航控制器或其他东西,都取决于你。