检测区域

@interface ViewController ()<CLLocationManagerDelegate>

/**  *  定位管理者  */

@property (nonatomic ,strong) CLLocationManager *mgr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 2.成为CoreLocation管理者的代理监听获取到的位置
    self.mgr.delegate = self;
   
    // 注意:如果是iOS8, 想进行区域检测, 必须自己主动请求获取用户隐私的权限
    if  ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0 )
    {
        [self.mgr requestAlwaysAuthorization];
    }
   
    // 3.开始检测用户所在的区域
    // 3.1创建区域
//    CLRegion 有两个子类是专门用于指定区域的
//    一个可以指定蓝牙的范围/ 一个是可以指定圆形的范围
   
    // 创建中心点
    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(40.058501, 116.304171);
   
    // c创建圆形区域, 指定区域中心点的经纬度, 以及半径
    CLCircularRegion *circular = [[CLCircularRegion alloc] initWithCenter:center radius:500 identifier:@"软件园"];
    //开始监控圆形区域
    [self.mgr startMonitoringForRegion:circular];
   
}

#pragma mark - CLLocationManagerDelegate
// 进入监听区域时调用
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    NSLog(@"进入监听区域时调用");
}
// 离开监听区域时调用
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
    NSLog(@"离开监听区域时调用");
}

posted @ 2015-12-28 18:16  akkeLyn  阅读(141)  评论(0编辑  收藏  举报