问题重述:
iOS 8中改变了通知注册的方式,如果App需要同时支持iOS 7 和 8 的话,需要首先检查selector。
解决方案:在Xcode 6中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
//-- Set Notification
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
//--- your custom code
return YES;
}
参考:
http://stackoverflow.com/questions/24454033/registerforremotenotificationtypes-is-not-supported-in-ios-8-0-and-later代码转载自:
http://stackoverflow.com/a/24773465/3458781
本文详细介绍了iOS8中通知注册方式的变化,并提供了在Xcode6中针对iOS7和8版本进行跨版本兼容的实现方法,通过检查selector来决定使用iOS7或iOS8的通知注册代码。

2万+

被折叠的 条评论
为什么被折叠?



