获取示例设备令牌

问题描述:

我想从我的iphone获取设备令牌。在阅读帖子后,我已经完成了这个工作。获取示例设备令牌

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert ]; 
} 
    (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{ 
    NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken); 
} 

我已经把didRegisterForRemoteNotificationsWithDeviceToken断点,但没有就此止步。我如何确保它被调用?

对不起,noob问题。需要在此方面的指导...

+1

找到完整的教程教程 - http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part -12 – 2013-05-03 03:39:50

+0

适用于您应用的Eanble推送通知(意味着将通知服务添加到您的供应配置文件)。然后重试。 – NSUserDefault 2013-05-03 03:47:39

可以有任何理由。

要么在生成.cer文件时做了错误的事情,要么在XCode中没有安装新的配置文件,因为在为PUSH NOTIFICATION SERVICES配置应用程序后删除了旧配置文件。

因此,在为应用程序配置苹果推送通知服务时,再次在供应门户中再次检查。并再次下载.cer文件。 然后从.cer文件生成.pem文件(它包含私钥)。 然后再次下载新的设置配置文件,然后从XCode中删除旧的设置并安装新的设置。

然后用这个:

#pragma mark - 
#pragma mark Push Notifications 
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken { 
    // Get a hex string from the device token with no spaces or < > 

    NSString *deviceToken = [[NSString alloc] init]; 

    deviceToken = [[[[_deviceToken description] 
        stringByReplacingOccurrencesOfString: @"<" withString: @""] 
        stringByReplacingOccurrencesOfString: @">" withString: @""] 
        stringByReplacingOccurrencesOfString: @" " withString: @""]; 

    NSLog(@"deviceToken = %@",deviceToken); 

    } 

希望它可以帮助你。

+0

不应该依赖描述 - 不保证保持不变。改为:[NSString stringWithFormat:@“%08x%08x%08x%08x%08x%08x%08x%08x”, ntohl(tokenBytes [0]),ntohl(tokenBytes [1]),ntohl(tokenBytes [ 2]), ntohl(tokenBytes [3]),ntohl(tokenBytes [4]),ntohl(tokenBytes [5]), ntohl(tokenBytes [6]),ntohl(tokenBytes [7])]'' – Mar0ux 2013-05-03 04:43:18

您必须为您的应用程序创建一个新的供应配置文件,并使用相同的方式为您的应用程序签名。您必须在设备中运行应用程序才能获取设备令牌。如果您在模拟器中运行应用程序,它将返回错误。

经历给

http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html