iOS8 定位新增功能

iOS诞生之日起,系统便配带了定位功能,随着无线互联网的需求,移动功能的日新月异的变化,以及iOS的不断升级,定位功能都有不断的更新,自iOS7加入了iBeacon,为无线移动推送提供了更多的变数以后,在iOS8里面定位功能也有不俗的表现。
Core Location framework
的变化主要有以下几点:
1. 
在定位状态中引入Always WhenInUse的概念。
2. 
加入Visit monitoring的特性这类特性特别适合旅行类别的应用,当用户到达某个指定的区域内,monitor开始作用。
3.
加入室内定位技术,增加CLFloor, 在室内可以得到楼层信息。

下面针对这三种分别详细的讲一下使用方法。

a.定位的种类分为:

持续的更新:location, background location, ranging (Always/WhenInUse work)
监视类的更新:region monitoring, significant location changes (Always work)
其中持续的后台位置更新,在程序前台的时候发起的,WhenInUse模式也可以得到正确的地理位置更新,但是如果是类似于从后台被唤起这种服务,则需要使用Always authorization

c. 增加了跳转到privacylink: UIApplicationOpenSettingsURLString当需要提示关闭了定位功能的用户使用定位的时候可以给通过如下的方式跳转到设定画面:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: UIApplicationOpenSettingsURLString]];

e. kCLAuthorizationStatus,由原来的kCLAuthorizationStatusAuthorized,变为kCLAuthorizationStatusAuthorizedAlwayskCLAuthorizationStatusAuthorizedWhenInUse

具体的使用方法:

A. 决定是否开启后台模式:在Target->capsbilities->backgourn modes
B. plist中增加WhenInUse/Always的提示文字,使用NSLocationWhenInUseUsageDescription /NSLocationAlwaysUseUsageDescription
C. 请求不同的服务:
地理位置变化:
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager startUpdatingLocation]
监听region:
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
CLCircularRegion *region = [[CLCircularRegion alloc]...];
[self.locationManager requestAlwaysAuthorization];
[self.locationManager startMonitoringForRegion:region];
获取地理位置并监听region:
plist里同时设置NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUseUsageDescription,调用方式可以参考上面,但是需要注意的是,always的时候可能需要对模式进行判断。
if (authorizationStatus == kCLAuthorizationStatusDenied || authorizationStatus == kCLAuthorizationStatusWhenInUse) {
// TODOdo what you want e.g. goto setting view
}
[self.locationManager requestAlwaysAuthorization];
[self.locationManager startMonitoringForRegion:region];
D: 集成的时候可以使用responsToSelector来避免iOS7.iOS8api不同引发的错误。
E: 对于只是在MKMapViewHtml5中使用的定位同样需要在plist中对提示增加自定义。

@interface CLLocationManager (CLVisitExtensions)

  • (void)startMonitoringVisits NSAVAILABLE(NA, 80); // 开启监视
  • (void)stopMonitoringVisits NSAVAILABLE(NA, 80); // 停止监视

当设备到达指定的地点时,系统会调用下面的方法来通知。

  • (void)locationManager:(CLLocationManager *)manager didVisit:(CLVisit *)visit; 具体可以拿到的信息。@interface CLVisit : NSObject @property (nonatomic, readonly, copy) NSDate *arrivalDate; @property (nonatomic, readonly, copy) NSDate *departureDate; @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; // center of region @property (nonatomic, readonly) CLLocationAccuracy horizontalAccuracy;

使用功能:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
[self.locationManager startUpdatingLocation]

<h5 500;="" color:="" #333333;\"="" style="font-size: 20px; margin: 0px; padding: 0px; font-weight: normal; letter-spacing: 0em; color: rgb(1, 35, 49); word-wrap: break-word !important;">回调:

  • (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { for (CLLocation *newLocation in locations) { CLFloor *floor = newLocation.floor; NSInteger level = floor.level; } }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值