区域监听

作者: IIronMan | 来源:发表于2016-06-29 18:04 被阅读123次
  • 区域顾名思义是一个指定的区域,对其进行监听。先普及一下一点知识
经纬度的基本知识

前提:加载一张指南针图片,其他的#import <CoreLocation/CoreLocation.h>框架都需要导入,以及定位管理对象,挂代理,遵守协议,利用对象来调用 startMonitoringForRegion:(nonnull CLRegion *),然后在对其设置

-下面是具体的代码

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController ()<CLLocationManagerDelegate>
@property(nonatomic,strong)CLLocationManager *locationManager;

@end

@implementation ViewController

//1.创建管理者对象  懒加载

-(CLLocationManager *)locationManager
{
  if (!_locationManager) {
    
    _locationManager = [[CLLocationManager alloc]init];
}

return _locationManager;
}


- (void)viewDidLoad {
[super viewDidLoad];

//2.挂代理,遵守协议

self.locationManager.delegate = self;

//注意:如果是ios8,想进入区域检测,必须自己主动请求获取用户隐私的权限
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) {
    
    //4.主动要求用户对我们的程序授权,授权状态改变就会通知代理status
    [self.locationManager requestAlwaysAuthorization];
    
}else
{
    NSLog(@"不是ios8");
}

//3.开始检测用户所在的区域(后面给一个区域)
//3.1.创建区域

//CLRegion有两个子类是专门用来指定区域的,一个可以指定蓝牙的范围,一个可以用来指定圆形的范围
//创建我们的中心点
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(40.058501, 116.304171);

CLCircularRegion *circular = [[CLCircularRegion alloc]initWithCenter:center radius:500 identifier:@"软件园"];

[self.locationManager startMonitoringForRegion:circular];

}

 #pragma mark -CLLocationMangerDelegate  代理方法的调用

//进入一个区域
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{

NSLog(@"进入监听区域");

}
//离开区域时调用
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{

NSLog(@"离开监听区域");

}

@end

相关文章

  • 回车 enter 键盘监听

    JS监听某个输入框 S监听某个DIV区域 JS监听body区域

  • 区域监听

    区域监听 1.概念解释 区 域 : 就是指划定的一块地域范围(比如圆形区域, 则由区域中心, 和半径组成) ...

  • 区域监听

    区域顾名思义是一个指定的区域,对其进行监听。先普及一下一点知识 前提:加载一张指南针图片,其他的#import <...

  • iOS 区域监听

    一、基本步骤 1.导入CoreLocation框架和对应的主头文件 #import

  • Swift区域监听

    监听代理

  • H5 实现下拉顶部放大

    1.监听整个下拉区域的touchstart事件,并记录下pageY和clientY值 2.监听整个区域的touch...

  • vue中使用watch监听$route 无效问题

    路由: 监听: 发现页面跳转时,并没有监听输出内容,就是没有监听到。路由组件的渲染区域为 router-view,...

  • 6.区域监听

    @interface ViewController() @property(nonatomic,strong)CL...

  • IntersectionObserver的使用

    IntersectionObserver用来监听一个目标元素是否出现在web页面的可视区域。 传统方式监听一个元素...

  • JS实现滚动条触底加载更多

    原理 1.通过监听滚动区域DOM的scroll事件, 计算出触底 // 滚动可视区域高度 + 当前滚动位置 ===...

网友评论

  • 吾是小马哥:同求demo(742395257@qq.com)
  • younger_times:老大,为什么我照着你敲的为什么没有任何反应?有没有demo?
    IIronMan: @younger_times 2318151015我发给你一个 demo

本文标题:区域监听

本文链接:https://www.haomeiwen.com/subject/evjxjttx.html