@interface ViewController()
@property(nonatomic,strong)CLLocationManager* manager;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a
nib.
CLLocationManager*
manager = [[CLLocationManageralloc]init];
manager.delegate=self;
self.manager= manager;
//请求用户授权
//[_manager requestWhenInUseAuthorization];//这个不能实现区域监听
[_manager requestAlwaysAuthorization];
[_manager startUpdatingLocation];
NSLog(@"is = %i",[CLLocationManagerisMonitoringAvailableForClass:[CLCircularRegionclass]]);
CLLocationCoordinate2D center =CLLocationCoordinate2DMake(21.123,121.345);
CLCircularRegion*
region = [[CLCircularRegion alloc]initWithCenter:center radius:1000 identifier:@"lyb"];
[_manager startMonitoringForRegion:region];//开始监听
}
- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion*)region {
NSLog(@"%s",__func__);
}
- (void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion*)region {
NSLog(@"%s",__func__);
}
@end