【问题标题】:Location Monitoring in iOS8 not workingiOS8中的位置监控不起作用
【发布时间】:2015-05-28 06:48:24
【问题描述】:

你能帮我解决位置监控的问题吗?didenter 和 didexit 永远不会被调用。顺便说一句,我正在 iPhone 上测试它。代码中是否还有其他需要更改或添加的内容。任何形式的帮助表示赞赏。 谢谢。

下面是代码:

- (void)viewDidLoad {

  _manager=[[CLLocationManager alloc]init];

  _mView.delegate=self;

[_manager requestWhenInUseAuthorization];
_manager.delegate=self;

_manager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;

_manager.distanceFilter=100;

[_manager startUpdatingLocation];
_mView.showsUserLocation=YES;

CLLocationCoordinate2D c;
c.latitude=33.420647;

c.longitude=-111.918893;

c=CLLocationCoordinate2DMake(c.latitude, c.longitude);

CLCircularRegion *circle=[[CLCircularRegion alloc]initWithCenter:c radius:100 identifier:@"string"];

if ([CLLocationManager isMonitoringAvailableForClass:[CLCircularRegion class]]) {

NSLog(@"yes");

[ _manager startMonitoringForRegion:circle];

circle.notifyOnEntry=YES;

circle.notifyOnExit=YES;
}


-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{

    NSLog(@"Inside");

    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Monitoring" 
    message:@"Inside" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *action=[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];

    [alert addAction:action];

    [self presentViewController:alert animated:YES completion:nil];

}


-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{

    NSLog(@"Outside");

    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Monitoring" message:@"Outside" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *action=[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];

    [alert addAction:action];

    [self presentViewController:alert animated:YES completion:nil];

}

【问题讨论】:

    标签: ios objective-c location monitoring clcircularregion


    【解决方案1】:

    您应该删除 [_manager startUpdatingLocation] 行,我认为您不需要调用它,因为您只想进行区域监控。

    【讨论】:

    猜你喜欢
    • 2015-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 2014-10-23
    • 2014-09-30
    • 2015-08-08
    • 2015-12-09
    相关资源
    最近更新 更多