无法检索设备令牌

发布于 2024-12-28 00:25:31 字数 1572 浏览 1 评论 0原文

我在客户端应用程序中将这些代码行实现到 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 下也有这些错误:

错误:权利“keychain-access-groups”具有配置配置文件不允许的值

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

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

你们知道问题出在哪里吗? 非常感谢

I implemented these lines of code in the client app into the appDelegate.m file :

    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]);
}
}

But didregisterForRemoteNotificationWithDeviceToken never gets called neither does didFailToRegisterForRemoteNotificationsWithError. I can find my app under settings>Notification on my device but cant retrieve the device token. Also under Xcode>Organizer>MyiPhone>Console there are those errors :

Error: entitlement 'keychain-access-groups' has value not permitted by a provisioning profile


Error: entitlement 'aps-environment' has value not permitted by a provisioning profile


Error: entitlement 'application-identifier' has value not permitted by a provisioning.

would you guys have any idea what the problem could be ?
Many thank

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红尘作伴 2025-01-04 00:25:31

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

My guess is that your entitlements file doesn't match what's in your provisioning profile. Try opening your provisioning profile with a text editor, you'll see a lot of garbage but you'll see what's listed for entitlements. Make sure you set your entitlements file to match what's in your provisioning profile exactly.

给我一枪 2025-01-04 00:25:31

试试这个代码。它肯定会帮助

- (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);
}

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

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

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

Try this code . It will definitely helps

- (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);
}

Create a new provisioning profile and enable push notification service.

Note : Your bundle identifier should be without wildcard character.

Please let me know if u still face any problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文