저는 지오 펜스를 만들고 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];
}
이러한 메서드는 colocation의 대리자를 self로 설정하더라도 나를 위해 호출되지 않습니다. – coolcool1994