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

来源:互联网 发布:网络用语dm是什么意思 编辑:程序博客网 时间:2024/05/16 09:48

跳转到系统 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];    [[UIApplication sharedApplication] registerForRemoteNotifications]; //或者使用"在 APPDelegate 中对应位置添加" 2选1    } else {        //原来注册通知的代码        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];    }

在 APPDelegate 中对应位置添加

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {  if (notificationSettings.types != UIUserNotificationTypeNone) {    [application registerForRemoteNotifications];  }}
0 0
原创粉丝点击