应用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"]]; }

当服务关闭时:

最新文章

  1. 32-bit ALU [Verilog]
  2. AngularJs angular.forEach、angular.extend
  3. Android在TextView中实现RichText风格
  4. Java 或者android 的加密技术
  5. mysql 关联条件与查询(过滤)条件
  6. Nginx基础知识之——配置文件信息(检查配置文件是否正确)
  7. 一模 (1) day2
  8. windows 8.1 pro X64安装中断
  9. memcached的基本命令(安装、卸载、启动、配置相关)
  10. php常用的排序算法与二分法查找
  11. SQL Server之记录筛选(top、ties、offset)汇总
  12. Kafka 0.10 Producer网络流程简述
  13. shell入门笔记1:执行方式、运行方式、变量、替换
  14. Convert Sorted Array to Binary Search Tree(将一个有序数组转换成一颗二叉搜索树)
  15. 2017年BackBox5和Ubuntu16.04.1国内更新源
  16. XML文档的简易增删查改
  17. 面试html部分
  18. android项目生成aar和引用aar解决方案
  19. 数据结构——基于java的链表实现(真正理解链表这种数据结构)
  20. 远程连接报错“This could be due to CredSSP encryption oracle remediation.”

热门文章

  1. Codeforces 1099 D. Sum in the tree-构造最小点权和有根树 贪心+DFS(Codeforces Round #530 (Div. 2))
  2. mysql-错误备查
  3. Loj#6433「PKUSC2018」最大前缀和(状态压缩DP)
  4. 发现一个FreeSWITCH bug
  5. [NOIP2015] D1T2 信息传递
  6. Codeforces Round #448(Div.2) Editorial ABC
  7. Spring中与Spring相关的注解
  8. django框架下celery+rabbitmq+flower完成异步任务
  9. 你一定喜欢看的 Webpack 2.× 入门实战(转载)
  10. iptables最常用的规则示例