系统定位在iOS8中的改变
CLLocationManager这个系统定位的类在iOS8之前要实现定位,只需要遵守CLLocationManagerDelegate这个代理即可:
- (void)startLocate
{
if([CLLocationManager locationServicesEnabled]){
_locManager = [[CLLocationManager alloc]init];
[self.locManager setDelegate:self];
[self.locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.locManager startUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
[_locManager stopUpdatingLocation];
CLLocation *currentLocation = [locations lastObject];
CLLocationCoordinate2D coor = currentLocation.coordinate;
NSString *latitude = @(coor.latitude).description;
NSString *longitude = @(coor.longitude).description;
}
iOS8之前以上两个方法正常的情况下,已经能够正常获取经纬度了。但是在iOS8下,则需要在startLocate这个方法中在CLLocationManager这个类实例化后添加如下代码:
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[ self.locManager requestAlwaysAuthorization];
}
但是仅仅添加以上代码还不行,还需要在工程的info.plist文件中添加键值对:
Key Type Value
NSLocationAlwaysUsageDescription Array/Dictionary/Boolean/Data/Date/Number/String
注意上方对应的Type,这七种类型都支持,我重点说说String和Boolean类型:
1.Type为String时:Value这个地方开发者可以根据需要说明定位的具体目的,让用户清楚的知道开启定位后用于做什么,更加透明化,清晰化;
弹框中"定位"两字即为Type为String时Value设置的值为"定位"时的展示。
当Value的值为空时,弹框显示如下:
2.Type为Boolean时:Value填YES即可。弹框显示如下:
而iOS8以前,定位提示的弹框显示如下:
在iOS8下如果不做以上两处的处理,系统CLLocationManager这个类即时指定了代理,其获取经纬度的代理方法也不会走。
系统定位在iOS8中的改变的更多相关文章
- iOS8中定位服务的变化(CLLocationManager协议方法不响应,无法回掉GPS方法,不出现获取权限提示)
最近在写一个LBS的项目的时候,因为考虑到适配iOS8,就将项目迁移到Xcode6.0.1上,出现了不能正常获取定位服务权限的问题. self.manger = [[CLLocationManager ...
- iOS8中使用CoreLocation定位[转]
本文转自:http://blog.devzeng.com/blog/ios8-corelocation-framework.html iOS8以前使用CoreLocation定位 1.首先定义一个全局 ...
- iOS8中的定位服务
iOS8中的定位服务 My app that worked fine in iOS 7 doesn't work with the iOS 8 SDK. CLLocationManager doesn ...
- ios中关于系统定位CLLocationManager的使用解析
//1.添加定位管理委托协议 CLLocationManagerDelegate //2.初始化定位管理对象 self.locationManager=[[CLLocationManager allo ...
- iOS8中 UILocalNotification 和 UIRemoteNotification 使用注意
先说一个关于UILocalNotification的知识点,容易被忘记: Each app on a device is limited to 64 scheduled local notificat ...
- 描述了say_hello函数的具体内容,调用zend_printf系统函数在php中打印字符串
下载一个php的源代码包,这里使用的是php 4.0.5版,解压后会看到php的根目录下会有README.EXT_SKEL这样一个文件,打开详细阅读了一下,发现了一个非常好用的工具,这个工具可以帮你构 ...
- iOS 学习笔记 九 (2015.04.02)IOS8中使用UIAlertController创建警告窗口
1.IOS8中使用UIAlertController创建警告窗口 #pragma mark - 只能在IOS8中使用的,警告窗口- (void)showOkayCancelAlert{ NSSt ...
- ios8中的UIScreen
let orientation: UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation pri ...
- iOS8中添加的extensions总结(一)——今日扩展
通知栏中的今日扩展 分享扩展 Action扩展 图片编辑扩展 文件管理扩展 第三方键盘扩展 注:此教程来源于http://www.raywenderlich.com的<iOS8 by Tutor ...
随机推荐
- javaSE基础06
javaSE基础06 一.匿名对象 没有名字的对象,叫做匿名对象. 1.2匿名对象的使用注意点: 1.我们一般不会用匿名对象给属性赋值的,无法获取属性值(现阶段只能设置和拿到一个属性值.只能调用一次方 ...
- cell单选
先上图给看看效果 cell单选逻辑就是取出上一个选中的cell 设置图片为默认图片 在取出点击的cell 设置图片为选中图片即可 废话不多说直接上代码 p.p1 { margin: 0.0px 0.0 ...
- centos 使用 locate
centos 第一次使用locate时报错: locate: can not stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录 因为locate相关的索 ...
- C#序列化
1.序列化一般有2种(XML和2进制),简单对象序列化 using System; using System.IO; using System.Runtime.Serialization.Format ...
- 协议分析TMP
最近闲来有事, 分析了一个非常低端(非常低端的意思是说你不应该对她是否能取代你现有的QQ客户端作任何可能的奢望,她只是一个实验性的东西)的手机QQ的协议, 是手机QQ3.0, 所用到的TCP ...
- Win10 VS2015自动添加头注释
/********************************************************************************** 作者: $username$** ...
- sizeof(转载)
原文地址:http://blog.sina.com.cn/s/blog_5da08c340100bmwu.html 转载至:http://www.cnblogs.com/wangkangluo1/ar ...
- sql 语句
INSERT 基本语法:INSERT INTO table_name VALUES(value1,value2,value3,...); 指定列:INSERT INTO table_name(colu ...
- prototype 和__proto__
//Animal构造函数 function Animal(name){ this.name = name; } //Animal原型对象 Animal.prototype = { id:"A ...
- [leetcode] 小心成环
156. Binary Tree Upside Down Given a binary tree where all the right nodes are either leaf nodes wit ...