ios 定位 监听是否跨入某个指定的区域
/*****监听用户是否进入和走出 在某个区域*****/
1 #import "ViewController.h"
#import <CoreLocation/CoreLocation.h> @interface ViewController ()<CLLocationManagerDelegate> /** */
@property (nonatomic, strong) CLLocationManager *locationM; @property (weak, nonatomic) IBOutlet UILabel *notice;
@end @implementation ViewController #pragma mark - 懒加载
/** 位置管理者属性的懒加载 */
-(CLLocationManager *)locationM
{
if (!_locationM) {
_locationM = [[CLLocationManager alloc] init];
_locationM.delegate = self; if([[UIDevice currentDevice].systemVersion floatValue] >= 8.0)
[_locationM requestAlwaysAuthorization]; }
return _locationM;
} - (void)viewDidLoad { // 参数, 必须继承自 clregion
if ([CLLocationManager isMonitoringAvailableForClass:[CLCircularRegion class]]) { // 1. 创建区域
// 1. 1 确定区域中心
CLLocationCoordinate2D center = {21.123, 121.345}; // 1.2 区域半径
CLLocationDistance distance = ;
//2128000.000000 最大监控限度
if (distance > self.locationM.maximumRegionMonitoringDistance) {
distance = self.locationM.maximumRegionMonitoringDistance;
} CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:center radius:distance identifier:@"一个神秘的地方"]; /**以下两种方式都能监听 是否在区域 里面,建议用监控状态的方式 .下面两种方式都写出来了**/ //-------######-----(方式一 start)------------
54
55 // 2. 监听区域(会调用 didEnterRegion 和 didExitRegion 方法)
56 // [self.locationM startMonitoringForRegion:region];
57 //-------######-----(方式一 end )------------ //-------######-----(方式二 start)------------ // 请求某个区域当前状态(在后台也可以监听到某个区域)
63 /***
64 CLRegionStateUnknown,
65 CLRegionStateInside,
66 CLRegionStateOutside
67 **/
68
69 // 2. 监听状态(会调用 didDetermineState 方法)
70 [self.locationM requestStateForRegion:region]; //------######------(方式二 end)------------ } } #pragma mark - CLLocationManagerDelegate 代理方法 /**
* 进入区域
*
* @param manager 位置管理者
* @param region 区域
*/
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"进入区域---%@", region.identifier);
self.notice.text = @"欢迎来到一个神秘的地方, 给你钱";
} /**
* 离开区域
*
* @param manager 位置管理者
* @param region 区域
*/
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"离开区域---%@", region.identifier);
self.notice.text = @"祝你们有大好前途";
}
/**
* 注册区域失败调用
*
* @param manager 位置管理者
* @param region 区域
* @param error 错误信息
*/
-(void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{ // 移除距离较远的region
// [self.locationM stopMonitoringForRegion:region比较远的region ] } /**
* 当我们请求区域状态时调用
*
* @param manager 位置管理者
* @param state 状态
* @param region 区域
*/
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if(state == CLRegionStateInside)
{
self.notice.text = @"欢迎来到一个神秘的地方, 给你钱";
} if (state == CLRegionStateOutside) {
self.notice.text = @"祝你们有大好前途"; }
} @end
ios 定位 监听是否跨入某个指定的区域的更多相关文章
- iOS如何监听弱网?
场景: iOS中我们可能经常用到监听网络,不过大部分是监听网络的类型,即2G/3G/4G WIFI,是否连接网络,然而测试人员对APP进行测试时候经常会有一个弱网测试,即在弱网环境下对APP进行测试, ...
- iOS 实时监听app的网络连接状态
实际iOS开发中,在网络通信中我们大部分使用第三方(只谈短链),譬如 AFNetworking.ASIHttpRequest(这个停更了,想必现在没多少人用),swift的 Alamofire 等. ...
- Android实现短信监听并且转发到指定的手机号,转发后不留痕
转载:http://blog.csdn.net/swqqcs/article/details/7252419 通过这些代码也可以对远程手机实现短信控制.有兴趣的可以自己改一下,说一下简单的原理,要实现 ...
- iOS,监听tableVIew的偏移量
1. 添加监听 [self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObs ...
- iOS 网络监听、判断
一 网络监听 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary ...
- iOS 关于监听手机截图,UIView生成UIImage, UIImage裁剪与压缩的总结
一. 关于监听手机截图 1. 背景: 发现商品的售价页总是被人转发截图,为了方便用户添加截图分享的小功能 首先要注册用户截屏操作的通知 - (void)viewDidLoad { [super vi ...
- ios --键盘监听JYKeyBoardListener
没有前言,就是一个简单的键盘监听,自动调整输入框的位置不被键盘遮挡 .h // // JYKeyBoardListener.h // // Created by JianF.Sun on 17/9/2 ...
- iOS自学-监听按钮点击、提醒框
//事件监听的问题 CGRect btn2Frame = CGRectMake(100.0, 150.0, 60.0, 44.0); //两种不同的方式创建 UIButton *btn2 = [UIB ...
- iOS键盘监听事件
1.注册键盘通知事件 NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; // 键盘将出现事件监听 [center ...
随机推荐
- UIWebView用法详解及代码分享
今天我们来详细UIWebView用法.UIWebView是iOS内置的浏览器控件,可以浏览网页.打开文档等 能够加载html/htm.pdf.docx.txt等格式的文件. 用UIWebView我们就 ...
- GET/POST请求的使用《极客学院 --AFNetworking 2.x 网络解析详解--2》学习笔记
AFNetworking是开源代码排名第一的开源库. GET请求的请求正文 一般都是明文显示的,携带的数据量小. POST用于处理复杂的业务,并不用明文的请求,其实POST请求可以携带更多的参数,只 ...
- UVa 107 - The Cat in the Hat (找规律,注意精度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- Force.com平台基础
当我开始写这篇博客的时候,<Force.com Platform Fundamentals>的PDF版本我还没看到十分之一.由于PDF全部是英文的,所以我看起来比较吃力.我尝试过边看边做笔 ...
- Spring自定义一个拦截器类SomeInterceptor,实现HandlerInterceptor接口及其方法的实例
利用Spring的拦截器可以在处理器Controller方法执行前和后增加逻辑代码,了解拦截器中preHandle.postHandle和afterCompletion方法执行时机. 自定义一个拦截器 ...
- Centos开机自启动redis
修改redis.conf,打开后台运行选项: # By default Redis does not run as a daemon. Use 'yes' if you need it. # Note ...
- C++STL之迭代器2
在学习c++ STL的时候,整天碰到迭代器,也整天用,但是,到底它是个什么东西,很多人没有一个认识.这里我通过几个小的DEMO,来看看迭代器.首先我实现了一个十分简陋的vector类: templat ...
- SQL Server with(nolock)详解
大家在写查询时,为了性能,往往会在表后面加一个nolock,或者是with(nolock),其目的就是查询是不锁定表,从而达到提高查询速度的目的. 什么是并发访问:同一时间有多个用户访问同一资源,并发 ...
- Oracle索引(B*tree和Bitmap)学习
在Oracle中,索引基本分为以下几种:B*Tree索引,反向索引,降序索引,位图索引,函数索引,interMedia全文索引等,其中最常用的是B*Tree索引和Bitmap索引. (1).与索引相关 ...
- SOS: gnuplot fdtd的一个问题求助 perl vs python
我用perl和python写了相同功能的一段程序,计算一维fdtd,用gnuplot动态显示,可是python的数据没有显示出来,看横纵坐标的变化数据是正确收到了的,如最后的图片,求大神指点,谢谢. ...