iOS设备定位服务开启判定
2013-11-13 09:51
183 查看
应用CLLocationManager 的两个方法
[CLLocationManagerlocationServicesEnabled] 判断设备是否开启定位功能
[CLLocationManagerauthorizationStatus] 判断设备是否允许本程序的定位服务
使用:
当服务关闭时:
[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"]]; }
当服务关闭时:
相关文章推荐
- iOS开发效率的开源类库及工具
- iOS开发者可为每款App生成100个兑换码
- Xcode 5.0 下载,安装,使用 & iOS开发 -应用管理使用 xib及mvc封装
- iOS-知识大总结
- ios开发-引导页实现
- iOS CoreAnimation
- iOS7应用开发4、Foundation框架
- ios开发-引导页实现
- iOS GCD 拾遗
- ios小项目——新浪微博客户端总结
- 移动开发 meta参数参考
- IOS字体
- iOS URL网址中包含中文
- ios 内置付费 iap
- 实战ios Plist 读 写操作及修改 删除 排序
- IOS推送证书的制作
- iOS 多快好省的宏
- ios运行流程
- 将 protobuf 打包成 iOS 静态库 xcode4.6.2
- 讲解 Box2D (iOS) 的好站