您的位置:首页 > 移动开发

APP 适配 iOS8,位置、通知等特性

2015-06-04 13:08 357 查看
跳转到系统 App 设置

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

位置访问添加 开始-结束 之间代码请求询问

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
//开始
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
[self.locationManager requestWhenInUseAuthorization];
}
//结束
[self.locationManager startUpdatingLocation];
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
接受推送通知添加如下

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
<span style="white-space:pre">	</span>[[UIApplication sharedApplication] registerForRemoteNotifications]; //<span style="color:#ff0000;">或者使用"在 APPDelegate 中对应位置添加" 2选1</span>
} else {
        //原来注册通知的代码
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }

在 APPDelegate 中对应位置添加

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
if (notificationSettings.types != UIUserNotificationTypeNone) {
[application registerForRemoteNotifications];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: