2015-05-28 46 views
-1

你能幫我關於位置監測... didenter和didexit永遠不會被調用。順便說一句,我正在iphone上測試它。代碼中是否還有其他內容需要更改或添加。任何形式的幫助表示讚賞。 謝謝。位置監測在iOS8不起作用

下面是代碼:

- (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]; 

} 

回答

0

你應該刪除[_manager startUpdatingLocation]行,我覺得你並不需要,因爲你只想區域監控調用此。

+0

請這個答案http://stackoverflow.com/questions/25178981/geo-fencing-didenterregion-and-didexitregion-methods-not-called –