iOS设备定位服务开启判定
2024-10-15 05:59:56
应用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"]]; }
当服务关闭时:
最新文章
- 32-bit ALU [Verilog]
- AngularJs angular.forEach、angular.extend
- Android在TextView中实现RichText风格
- Java 或者android 的加密技术
- mysql 关联条件与查询(过滤)条件
- Nginx基础知识之——配置文件信息(检查配置文件是否正确)
- 一模 (1) day2
- windows 8.1 pro X64安装中断
- memcached的基本命令(安装、卸载、启动、配置相关)
- php常用的排序算法与二分法查找
- SQL Server之记录筛选(top、ties、offset)汇总
- Kafka 0.10 Producer网络流程简述
- shell入门笔记1:执行方式、运行方式、变量、替换
- Convert Sorted Array to Binary Search Tree(将一个有序数组转换成一颗二叉搜索树)
- 2017年BackBox5和Ubuntu16.04.1国内更新源
- XML文档的简易增删查改
- 面试html部分
- android项目生成aar和引用aar解决方案
- 数据结构——基于java的链表实现(真正理解链表这种数据结构)
- 远程连接报错“This could be due to CredSSP encryption oracle remediation.”
热门文章
- Codeforces 1099 D. Sum in the tree-构造最小点权和有根树 贪心+DFS(Codeforces Round #530 (Div. 2))
- mysql-错误备查
- Loj#6433「PKUSC2018」最大前缀和(状态压缩DP)
- 发现一个FreeSWITCH bug
- [NOIP2015] D1T2 信息传递
- Codeforces Round #448(Div.2) Editorial ABC
- Spring中与Spring相关的注解
- django框架下celery+rabbitmq+flower完成异步任务
- 你一定喜欢看的 Webpack 2.× 入门实战(转载)
- iptables最常用的规则示例