【发布时间】:2012-02-06 14:18:25
【问题描述】:
我正在处理推送通知。我编写了以下代码来获取设备令牌。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
NSLog(@"Registering for push notifications...");
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(@"This is device token%@", deviceToken);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"Error %@",err);
}
我能够在设备上成功运行应用程序,但无法在控制台上获取设备 ID。
我对认证和配置文件没有任何问题。
【问题讨论】:
-
你关注all the steps了吗?如果您在认证和提供以及代码方面没有任何问题,那么您一定是犯了一些小错误。就像..告诉我,您是否在与您的系统连接相同的真实设备上运行该应用程序?您是否还注意到您是否在控制台日志中获取设备令牌? Have you enable Push notification in iPhone?
-
我无法在控制台日志中获取设备令牌。
-
我在真机上运行应用程序没有任何错误。
-
您是否按照 iPhone 上的链接启用了 APNS?
-
是的,我启用了 APNS..但是设备令牌无法在 cosole 上获取
标签: ios iphone push-notification apple-push-notifications appdelegate