推送通知停止工作IOS 8
问题描述:
我有我的应用程序使用支持推送通知功能的企业证书签名。它工作正常,当我更新iPhone到iOS 8推送通知停止工作。经过调试和研究之后,我开始知道下面的代码需要添加以从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
}
但是,我们不会遇到与我们的应用程序的应用程序版本和所有工作良好的这个问题。它仅仅是在企业认证方面打破了什么?
答
您忘却一行代码:[[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];
}
有你在你的info.plist文件中添加 “NSLocationWhenInUseUsageDescription”? – Urmi 2014-09-26 10:10:31
是否真的需要推送通知? – Pankaj 2014-09-26 10:37:06
是的。是吗。否则应用程序将无法接收推送通知。 [链接](https://developer.apple.com/library/prerelease/iOS/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html)在讨论部分中检查以下行:“用户提示包含NSLocationWhenInUseUsageDescription键中的文本在您应用程序的Info.plist文件中,调用此方法时需要该键的存在。“ – Urmi 2014-09-26 10:47:43