我的应用程序使用支持推送通知功能的企业证书进行签名。它工作正常,当我将iphone更新到iOS 8推送通知停止工作。在我进行调试和一些研究之后,我开始知道要添加以下代码以从iOS 8开始检索推送令牌。
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) //>iOS8
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}else {// <iOS8
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
Add following callback methods,
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
//handle the actions
}
但是我们的应用程序的appstore版本并没有遇到这个问题,并且一切正常。它只是在企业认证上被打破了吗?
答案 0 :(得分:0)
您忘记了行代码:[[UIApplication sharedApplication] registerForRemoteNotifications];
类似的东西:
if ([application respondsToSelector: selector (registerUserNotificationSettings :)]) {
UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound
categories: nil ];
[[UIApplication sharedApplication] registerUserNotificationSettings: settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
}