区域监听用到的方法

  • [self.mgr startMonitoringForRegion:region]; --> 开启区域监听,没有返回值,在代理方法中得到信息并且处理信息 注:该方法只有用户位置发生变化的时候,相应的代理方法才会触发
  • [self.mgr requestStateForRegion:region]; -->根据指定区域请求一下用户现在的位置状态(CLRegionStateUnknown, CLRegionStateInside, CLRegionStateOutside),没有返回值,同样也是在代理方法中处理信息 注:该方法在程序一启动就会请求用户的位置状态.同样当用户位置发生变化时,也会触发相应的代理方法
  • - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region --> 进入指定区域后执行的代码
  • - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region --> 离开指定区域后执行的代码
  • - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region --> 在指定区域内确定了状态后触发的代理方法

区域监听的练习以及练习中的细节处理

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h> @interface ViewController ()<CLLocationManagerDelegate>
/** 位置管理者 */
@property(nonatomic,strong) CLLocationManager *mgr;
@property (weak, nonatomic) IBOutlet UILabel *msgLabel; @end @implementation ViewController #pragma mark - 懒加载
- (CLLocationManager *)mgr
{
if (_mgr == nil) {
_mgr = [[CLLocationManager alloc] init];
_mgr.delegate = self;
// 区域监听,监听的是用户,所以应该让用户授权获取用户当前位置
if ([_mgr respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[_mgr requestAlwaysAuthorization];
}
}
return _mgr;
} - (void)viewDidLoad {
[super viewDidLoad]; // ###细节二:判断设备是否支持区域监听(指定区域类型,一般是圆形区域)
if (![CLLocationManager isMonitoringAvailableForClass:[CLCircularRegion class]]) {
return;
} // 0.给定一个区域
// 0.1 区域的中点坐标
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(22.22, 33.33);
// 0.2区域半径
CLLocationDistance distance = 1000.0;
// ###细节一:半径有限制
if (distance > self.mgr.maximumRegionMonitoringDistance) {
distance = self.mgr.maximumRegionMonitoringDistance;
}
CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:center radius:distance identifier:@"Chaos"]; // 1.开启区域监听 代理中操作 -- 该方法只有用户位置发生了移动才会触发
// [self.mgr startMonitoringForRegion:region];
// 1.根据指定区域请求一下监听到的状态 代理中操作 -- 该方法在程序启动就会监听一下用户的位置
// 同样当用户位置发生变化时,也会触发相应的代理方法
[self.mgr requestStateForRegion:region];
} #pragma mark - CLLocationManagerDelegate /**
* 进入指定区域后指定的代码
*
* @param manager 位置管理者
* @param region 指定的区域
*/
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"进入区域--");
self.msgLabel.text = @"欢迎光临--";
}
/**
* 离开指定区域后执行的代码
*
* @param manager 位置管理者
* @param region 指定的区域
*/
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"离开区域--");
self.msgLabel.text = @"下次再来--";
} - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
/*
CLRegionStateUnknown, 不知道
CLRegionStateInside, 进入区域
CLRegionStateOutside 离开区域
*/
if (state == CLRegionStateInside) { self.msgLabel.text = @"欢迎光临";
} else if (state == CLRegionStateOutside) { self.msgLabel.text = @"下次再来";
}
} @end

iOS地图 -- 区域监听的实现和小练习的更多相关文章

  1. 【iOS】7.4 定位服务->2.1.3.3 定位 - 官方框架CoreLocation 功能3:区域监听

    本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正. 本文相关目录: ================== 所属文集:[iOS]07 设备工具 === ...

  2. (七十六)CoreLocation(二)获取经纬度、速度、方向,进行区域监听

    上节说明了如何在iOS7和iOS8上完成授权,并且开始获取位置,这一节介绍获取位置信息的方法. [定位精度] 定位精度有多种选择:根据字面意思即可理解 extern const CLLocationA ...

  3. 类似吸顶功能解决ios不能实时监听onscroll的触发问题

    问题:近期项目需要一个类似西东功能,当页面向上滚动160px后div固定在顶部 解决方法:首先,想到的是window.onscroll方法 .fixed{position:fixed;-webkit- ...

  4. iOS 键盘的监听 调整view的位置

    iOS在处理键盘的出现和消失时需要监听UIKeyboardWillChangeFrameNotifications/UIKeyboardDidHideNotifications - (void)vie ...

  5. IOS开发:监听来电状态的改变。

    #import <CoreTelephony/CTCallCenter.h> #import <CoreTelephony/CTCall.h> @property(nonato ...

  6. 【iOS】通知监听

    下例为:监听文本框  accountField  内容的改变, 当发生改变时, 调用textChange方法(多次).监听结束需要移除通知. - (void)viewDidLoad { [super ...

  7. iOS: 使用KVO监听控制器中数组的变化

    一.介绍: KVO是一种能动态监听到属性值的改变的方式,使用场景非常广泛,这里我只讲如何监听控制器ViewController中数组的变化. 二.了解: 首先我们应该知道KVO是不能直接监听控制器Vi ...

  8. ios应用来电监听

    先导入这两个头文件,库文件不用导可以 #import <CoreTelephony/CTCallCenter.h> #import <CoreTelephony/CTCall.h&g ...

  9. 移动端(IOS)iframe监听不到 onscroll 事件

    问题描述: 我在一个页面A中有瀑布流,点击瀑布流中的图片需要进入到另外一个页面B,点击返回需要回到页面A中点击的位置,为了实现该效果所以在页面A中嵌入iframe,iframe指向页面B,页面B中同样 ...

随机推荐

  1. iOS之App加急审核详细步骤

    申请加急网址:https://developer.apple.com/appstore/contact/appreviewteam/index.html 补充:加急审核说明是可以写中文的 提交加急审核 ...

  2. iOS模态弹出半透明视图控制器

    项目中需要实现点击按钮出现的视图全屏覆盖,呈半透明状态可以看到下面的视图? 解决方案: 绕了很多弯路原来可以使用模态弹出一个视图控制器 在iOS8之后只需要设置一个最新的属性 SecondViewCo ...

  3. TortoiseSVN和VisualSVN-Server的配置使用,外网访问SVN版本库

    TortoiseSVN和VisualSVN-Server的配置使用,外网访问SVN版本库 SVN客户端程序:TortoiseSVN SVN服务器程序:VisualSVN-Server ######## ...

  4. PS技巧:如何优雅的抠公章?

    搞设计的很苦逼,整天面对各种各样任务,除了修图.排版外,还时不时会有些另类需求.这时如果掌握一些小技巧就不用临时抱佛脚啦. 下面献上一计:教大家怎么用PS抠公章.有需要的拿去,PS:不要干坏事吆! 效 ...

  5. ORACLE告警日志文件

    告警日志介绍 告警日志文件是一类特殊的跟踪文件(trace file).告警日志文件命名一般为alert_<SID>.log,其中SID为ORACLE数据库实例名称.数据库告警日志是按时间 ...

  6. 在cmd和terminal怎么粘贴?

    在osx, linux的terminal 以及windows的 cmd实现粘贴是coder经常要做的事,鼠标右键,下拉菜单中单击粘贴paste.但是这显得笨拙,及其不快捷.但是正常使用的command ...

  7. SQL Server 2008 R2——使用数字辅助表(master..spt_values)实现用计数字段对记录进行重复显示

    =================================版权声明================================= 版权声明:原创文章 谢绝转载  请通过右侧公告中的“联系邮 ...

  8. 把Tomcat注册为windows服务

    配置环境变量 JAVA_HOME=D:\java CLASSPATH=.;%JAVA_HOME%\lib; PATH=%JAVA_HOME%\bin; 提示:一般jre默认在jdk目录下%JAVA_H ...

  9. 【小白的CFD之旅】04 任务

    和老蓝见面之后的很长一段时间里,小白都没有接到任何老蓝的消息,再加上课比较多,小白也慢慢适应了白天上课,晚上窝在宿舍打游戏,偶尔也去图书馆看看书的生活,这样宁静的生活持续了差不多两个月.就在老蓝的影子 ...

  10. [WPF系列]基础 Listening to Dependency Property change notifications of a given Element

    I want to share this great post from Anoop that shows a easy way to add a notification system to dep ...