区域监听需要开启授权 alwaysAllAu.. info.plist
-(CLLocationManager *)locationManger{
if(_locationManger == nil){
_locationManger = [[CLLocationManager alloc]init];
_locationManger.delegate = self;
[_locationManger requestAlwaysAuthorization];
}
return _locationManger;
}
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}(void)touchesBegan:(NSSet
pragma -mark 补充方法 更新区域中的状态
//2.请求区域的状态
[self.locationManger requestStateForRegion:region];
}
pragma -mark 区域监听的代理方法
//用代理方法监听,对象进入没该区域
//进入到一个区域中
-(void)locationManager:(CLLocationManager )manager didEnterRegion:(CLRegion )region{
NSLog(@”进入该区域,%@”,region.identifier);
}
-(void)locationManager:(CLLocationManager )manager didExitRegion:(CLRegion )region{
NSLog(@”离开该区域,%@”,region.identifier);
}
(void)locationManager:(CLLocationManager )manager didDetermineState:(CLRegionState)state forRegion:(CLRegion )region{
NSLog(@”%zd”,state); // == state=1 == 进入 state=2 == 离开
}