Apple推送通知中的“无效令牌”

时间:2014-09-02 03:47:39

标签: azure-mobile-services

我们无法让Apple推送通知在Azure移动服务上运行。我们已经上传了生产证书并尝试了发送,但每次它都会返回一个"无效令牌"错误。我们传递的示例设备令牌是' g4eaa50c3fdc3b97dc7ff0b4e745593e7b9bdae36d6e4ca78e4146a086c5be1a'。

请帮忙。

1 个答案:

答案 0 :(得分:0)

在您应用的app委托中,请输入以下代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];  
    return YES;
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
    NSString *deviceTokenString = [[[[deviceToken description]
                                     stringByReplacingOccurrencesOfString: @"<" withString: @""]
                                    stringByReplacingOccurrencesOfString: @">" withString: @""]
                                   stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSLog(@"Device Token === %@", deviceTokenString);
}



- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
    NSLog(@"Error in getting Device Token === %@", error);
}

然后在设备上运行您的应用。执行此操作时,系统将要求您提供显示应用程序中的推送消息的权限。如果允许,则调用方法didRegisterForRemoteNotificationsWithDeviceToken,并在控制台上打印您的设备令牌。