2012-07-31 5 views
1

저는 지오 펜스를 만들고 CLLocationManager 및 startMonitoringForRegion :을 사용하여 모니터하려고합니다. 문제는 내 대리자가 전화를받지 못하는 것뿐만 아니라 (예, 모든 메서드를 구현했습니다) 지역이 [locationManager moniteredRegions] 집합에 저장되지 않고 있다는 것입니다. 아래의 코드를 실행 한 후 로그를 보여줍니다startMonitoringForRegion이 영역을 만들지 않습니다.

2012-07-31 13 : 46 : 54.208 GeofencingTest [2357 : F803] 만든 지역 :

예 - 나는 regionMonitoringEnabled 및 regionMonitoringAvailable을 검사 한을. 아니요 - 저는이 장치를 시뮬레이터에서만 시도하지 않았습니다. 예 - [locationManager startUpdatingLocation] 및 CLLocation * location = locationManager.location을 수행하여 CLLocationManager에서 위치 업데이트를 가져올 수 있습니다.

도와주세요! :)

LocationDelegate.m

- (void) createGeofence:(NSString *)identifier withCenter:(CLLocationCoordinate2D)center withRadius:(CLLocationDistance) radius{ 
    if ([CLLocationManager regionMonitoringEnabled] && [CLLocationManager regionMonitoringAvailable]){ 
     CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:center radius:radius identifier:identifier]; 
     NSLog(@"should be succesful"); 
     [locationManager startMonitoringForRegion:region]; 
    } 

    NSLog(@"Created regions:"); 
    for (CLRegion *my_region in [locationManager monitoredRegions]){ 
     NSLog(@" Region: %@", my_region.identifier); 
    }  
} 
- (id) init{ 
    self = [super init]; 
    if (self){ 
     locationManager = [[CLLocationManager alloc] init]; 
     locationManager.delegate = self; 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    } 
    return self; 
} 

SomeOtherClass.m

- (IBAction)createGeofence:(UIButton *)sender{ 



    float latitude = [latitudeField.text floatValue]; 
    float longitude = [longitudeField.text floatValue]; 
    CLLocationDistance radius = [radiusField.text floatValue]; 

    CLLocationAccuracy desiredAccuracy = [self getAccuracyConvertedToMeters]; 

    [self.locationManagerObject createGeofence:identifierField.text 
            withCenter:CLLocationCoordinate2DMake(latitude, longitude) 
            withRadius:radius 
           withAccuracy:desiredAccuracy]; 

}

답변

0

그것은 수도 당신이 만든 영역을 로그인 할 때,이 지역이되지 않았 음을 수 아직 모니터되었습니다. 나는 지역 모니터링의 대리인 방법을 호출하고 모니터링 된 지역을 찾아 봐야한다고 생각합니다.

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region { 
    NSLog(@"Start monitoring for region: %@", region.identifier); 
    for (CLRegion *my_region in [manager monitoredRegions]){ 
     NSLog(@"Region: %@", my_region.identifier); 
    } 
} 

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error { 
    NSLog(@"Error: %@", error); 
} 
+0

이러한 메서드는 colocation의 대리자를 self로 설정하더라도 나를 위해 호출되지 않습니다. – coolcool1994

관련 문제