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 ...
随机推荐
- iOSQuartz2D-04-手动剪裁图片并保存到相册
实现效果 操作步骤 绘制一个矩形框,弹出一个alertView,提示是否保存图片 点击"是",将图片保存到相册 在相册中查看保存的图片 效果图 实现思路 在控制器的view上添加一 ...
- 解决Junit单元测试 找不到类 ----指定Java Build Path
做junit 单元测试时,发现怎么执行都是以前编译过得代码. 最后找到原因了, src/test/java 编译完的.class路径是 Default output folder Default ou ...
- mysql集群之MYSQL CLUSTER
1. 参考文档 http://xuwensong.elastos.org/2014/01/13/ubuntu-%E4%B8%8Bmysql-cluster%E5%AE%89%E8%A3%85%E5%9 ...
- db2操作 连接、备份、恢复db2
先deactivate后再start standby再primary报错不能启动hadr standby的时候,先restore,但是别rollback,直接start hadr as standby ...
- chrome和搜狗浏览器的js问题
1.在chrome中如果是js添加颜色必须用"#00CC00",必须加#号...不然会出问题,但是在搜狗浏览器中可以没有#号也能正确识别...
- Effective Java 65 Don't ignore exceptions
Principle An empty catch block defeats the purpose of exceptions, which is to force you to handle ex ...
- UC 浏览器远程调试手机web网页记录
浏览器远程调试插件有很多,本来要使用chrome浏览器的调试插件的,但是需要FQ才能使用(公司网络有限制,果断放弃),最终选择使用UC浏览器的. 其实UC官网插件使用已经介绍的很详细了,但是有几处坑需 ...
- 烂泥:kickstart无人值守安装CentOS6.5
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 在本次实验进行之前,首先我们要把公司的网络环境进行介绍. 注意这个网络拓扑图,也是生产环境的一个实例.同时服务器192.168.1.214已关闭ipta ...
- 初识zookeeper(一)之zookeeper的安装及配置
1.简要介绍 zookeeper是一个分布式的应用程序协调服务,是Hadoop和Hbase的重要组件,是一个树型的目录服务,支持变更推送.除此还可以用作dubbo服务的注册中心. 2.安装 2.1 下 ...
- TarJan 算法求解有向连通图强连通分量
[有向图强连通分量] 在有向图G中,如果两个 顶点间至少存在一条路径,称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G是一个强连通图.非强连通图有向图的 ...