无法检索设备令牌
我在客户端应用程序中将这些代码行实现到 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的猜测是您的权利文件与您的配置文件中的内容不匹配。尝试使用文本编辑器打开您的配置文件,您会看到很多垃圾,但您会看到列出的权利内容。确保您设置的权利文件与您的配置文件中的内容完全匹配。
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.
试试这个代码。它肯定会帮助
创建新的配置文件并启用推送通知服务。
注意:您的包标识符不应包含通配符。
如果您仍然遇到任何问题,请告诉我。
Try this code . It will definitely helps
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.