【发布时间】:2013-09-13 11:37:14
【问题描述】:
我在我的第一个 viewcontroller 中调用设备令牌。而且我无法得到结果,因为设备令牌为空。下面是我在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];
}
当我在 Viewcontroller 中调用时:
NSString *token= [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"];
令牌为空。
【问题讨论】:
-
你在模拟器上试试吗?
-
用真机试试。
-
检查您的配置文件并在真实设备中构建。
标签: iphone ios objective-c token devicetoken