0

我想用 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;

}

但什么也没发生。怎么了?

4

1 回答 1

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

alloc你的视图控制器之后,你也应该init这样做。并以模态方式或在导航控制器或其他方式呈现它,这取决于您。

于 2012-06-06T13:27:15.297 回答