iOS——判断当前应用是否允许定位
2016-12-09 11:54
441 查看
判断用户是否开启了定位功能:if ([CLLocationManager locationServicesEnabled] &&
([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized
|| [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)) {
//定位功能可用,开始定位
_locationManger = [[CLLocationManager alloc] init];
_locationManger.delegate = self;
[_locationManger startUpdatingLocation];
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
NSLog(@"不可用");
}
如果不可用,则提醒用户前往设置中去设置开启定位,并为用户设置跳转路径:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"开启定位" message:@"The calendar permission was not authorized. Please enable it in Settings to continue." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *setting = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *appSettings = [NSURL URLWithString:[NSString stringWithFormat:@"%@",UIApplicationOpenSettingsURLString]];
[UIApplication.sharedApplication openURL:appSettings];
}];
UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alertController addAction:setting];
[alertController addAction:cancle];
[self presentViewController:alertController animated:YES completion:nil];
([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized
|| [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)) {
//定位功能可用,开始定位
_locationManger = [[CLLocationManager alloc] init];
_locationManger.delegate = self;
[_locationManger startUpdatingLocation];
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
NSLog(@"不可用");
}
如果不可用,则提醒用户前往设置中去设置开启定位,并为用户设置跳转路径:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"开启定位" message:@"The calendar permission was not authorized. Please enable it in Settings to continue." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *setting = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *appSettings = [NSURL URLWithString:[NSString stringWithFormat:@"%@",UIApplicationOpenSettingsURLString]];
[UIApplication.sharedApplication openURL:appSettings];
}];
UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alertController addAction:setting];
[alertController addAction:cancle];
[self presentViewController:alertController animated:YES completion:nil];
相关文章推荐
- ios 里如何判断当前应用的定位服务是否可用
- 转 ios 里如何判断当前应用的定位服务是否可用
- ios 里如何判断当前应用的定位服务是否可用
- ios 里如何判断当前应用的定位服务是否可用
- ios 里如何判断当前应用的定位服务是否可用
- 判断应用是否允许定位当前位置
- ios 里如何判断当前应用的定位服务是否可用
- ios 判断当前应用的定位服务是否可用
- 转 ios 里如何判断当前应用的定位服务是否可用
- iOS 判断当前APP是否开启定位服务,未开通点击确定进入设置里进行设置
- iOS~判断应用是否有定位权限
- 如何判断应用是否允许开启定位
- 判断一个坐标点是否在一个无规则的多边形内 (iOS定位服务与地图应用开发:高德地图开发)
- iOS 判断定位是否允许_跳转定位设置界面
- 【ios开发】如何判断当前网络连接状态(网络是否正常)
- (转)判断当前应用是否在最前台
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
- iOS 判断当前设备是否连接到网络
- 【ios开发】如何判断当前网络连接状态(网络是否正常)
- 判断当前应用是否在前台运行