一、简介
- 优点:
- 该框架可以使用block接收用户的位置
- 而corelocation框架定位使用代理进行传值-> 相比较而言corelocation框架定位代码比较分散
- 框架存在问题
- 此框架针对于iOS9.0 ,前台授权时,后台是无法获取用户位置
- 使用
- 下载框架(locationManager框架)
- 使用block进行定位(带delayUntilAuthorized参数的定位:超时时间从什么时候开始计算)(依然要配置info.plist文件对应的键值对)
- 通过定位请求ID分别取消定位(不会回调block)和强制完成定位(会回调block)
二、基本使用
#import "ViewController.h"
#import "INTULocationManager.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
INTULocationManager *locMgr = [INTULocationManager sharedInstance];
// delayUntilAuthorized 超时计时从什么时候开始
INTULocationRequestID requestID = [locMgr requestLocationWithDesiredAccuracy:INTULocationAccuracyCity
timeout:3.0
delayUntilAuthorized:NO
block:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {
if (status == INTULocationStatusSuccess) {
NSLog(@"---%@", currentLocation);
}else
{
NSLog(@"错误 %zd", status);
}
}];
// 强制完成定位,会执行block内容
// [[INTULocationManager sharedInstance] forceCompleteLocationRequest:requestID];
// 取消位置请求(不会回调block)
[[INTULocationManager sharedInstance] cancelLocationRequest:requestID];
}
- (void)subscript
{
INTULocationManager *locMgr = [INTULocationManager sharedInstance];
[locMgr subscribeToLocationUpdatesWithDesiredAccuracy:INTULocationAccuracyHouse
block:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {
if (status == INTULocationStatusSuccess) {
NSLog(@"定位");
}
else {
NSLog(@"失败");
}
}];
}
@end
网友评论