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

iOS设备定位服务开启判定

2013-11-13 09:51 183 查看
应用CLLocationManager 的两个方法

[CLLocationManagerlocationServicesEnabled] 判断设备是否开启定位功能

[CLLocationManagerauthorizationStatus] 判断设备是否允许本程序的定位服务

- (BOOL)isOnLocation
{
BOOL isOn = false;
if (([CLLocationManager locationServicesEnabled]) && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {
NSLog(@"定位已经开启");
isOn = true;
} else {
NSLog(@"定位未开启");
isOn = false;
}
return isOn;
}


使用:

if (![self isOnLocation]) {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"警告" message:@"您的定位服务没有打开,请在设置中开启" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"prefs:root=LOCATION_SERVICES"]];

}


当服务关闭时:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: