【问题标题】:Can't retrieve the device token无法检索设备令牌
【发布时间】:2012-01-19 14:29:02
【问题描述】:

我将客户端应用程序中的这些代码行实现到 appDelegate.m 文件中:

    NSLog(@"Registering for push notification..");
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | 
         UIRemoteNotificationTypeBadge |
         UIRemoteNotificationTypeSound)];


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

-(void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
//NSString *str = [NSString stringWithFormat:@"Error; %@", err];
NSLog(@"Error: %@", err);
}

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
for (id key in userInfo) {
    NSLog(@"key:%@, value: %@", key, [userInfo objectForKey:key]);
}
}

但是 didregisterForRemoteNotificationWithDeviceToken 永远不会被调用,didFailToRegisterForRemoteNotificationsWithError 也不会。我可以在我的设备上的设置>通知下找到我的应用程序,但无法检索设备令牌。在 Xcode>Organizer>MyiPhone>Console 下也有这些错误:

错误:权利“钥匙串访问组”具有配置文件不允许的值

错误:权利“aps-environment”具有配置文件不允许的值

错误:权利“应用程序标识符”具有配置不允许的值。

你们知道问题可能是什么吗? 非常感谢

【问题讨论】:

    标签: iphone ios push-notification


    【解决方案1】:

    我的猜测是您的权利文件与您的配置文件中的内容不匹配。尝试使用文本编辑器打开您的配置文件,您会看到很多垃圾,但您会看到列出的权利。确保您将您的权利文件设置为与您的配置文件中的内容完全匹配。

    【讨论】:

    • 我根据我的配置文件添加了一个权利文件,但仍然没有设备令牌!
    • 我仍然收到此错误!我不知道这是否有帮助,但我有一个用于推送通知的配置文件和多个配置配置文件。
    【解决方案2】:

    试试这个代码。肯定会有帮助的

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        NSString* deviceTokenStr = [deviceToken description];
        deviceTokenStr = [deviceTokenStr stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
        deviceTokenStr = [deviceTokenStr stringByReplacingOccurrencesOfString:@" " withString:@""];
        NSLog(@"Device token ===> %@",deviceTokenStr);
    
        NSString* myDeviceToken=deviceTokenStr;
    
        NSLog(@"device Token =%@", myDeviceToken);
    }
    

    创建新的配置文件并启用推送通知服务。

    注意:您的捆绑包标识符不应包含通配符。

    如果您仍然遇到任何问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多