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 ...
随机推荐
- 小波说雨燕 第三季 构建 swift UI 之 度假清单 学习笔记
最终的效果: <1>第一个场景: 1.本地化 界面简体中文化 Supporting Files - info.plist Localization native development r ...
- find / -name *.py | xargs grep "domain" | wc -l
http://world77.blog.51cto.com/414605/209125 http://blog.csdn.net/windone0109/article/details/2817792 ...
- 每日Scrum--No.7
Yesterday:学习和设计路线的编程 Today:编写代码 Problem:.在设计查询参观路线的时候,整个逻辑特别的混乱,设想了各种树,图以及网的遍历问题,但经过多次与同学的交流以及网上的查询资 ...
- 从源码分析 Spring 基于注解的事务
在spring引入基于注解的事务(@Transactional)之前,我们一般都是如下这样进行拦截事务的配置: <!-- 拦截器方式配置事务 --> <tx:advice id=&q ...
- linux编译安装MySQL
最近就想搞搞hadoop,然后装个MySQL,测试一下那个sqoop. MySQL这种东西,既然是开放源码的,那就源码安装吧. 下面是我的测试环境说明: VMware10+Ubuntu14.04 Ky ...
- 百度地图Api进阶教程-点击生成和拖动标注4.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Armstrong数
题目描述 在三位的整数中,例如153可以满足1^3 + 5^3 + 3^3 = 153,这样的数称之为Armstrong数.将所有的Armstrong数按小到大排序,试写出一程序找出指定序号的三位Ar ...
- [转]Worksheet.Change Event (Excel)
本文转自:https://msdn.microsoft.com/en-us/library/office/ff839775.aspx#AboutContributor Example The fo ...
- μc/osⅡ简化版任务机制浅析
去年玩过一阵单片机,也用过μc/osⅡ的系统,但是就理解内核而言,整个即时操作系统还是过于冗杂,很多的东西很不适合初学者来动手操作,多方查找我发现他的任务机制可以进行功能的进一步简化, 可以类似于任务 ...
- Java 嵌套解析 json
1.首先需要安装org.json.jar 2.类JSONObject用于创建一个json对象.其中的JSONObject.put(KEY, VALUE)用于向其中添加条目 3.JSONObject.g ...