Hiii,왜 호출하지 않는 Cllocationmanager 대리자 메서드를 사용하여 Geofence 추적을 수행합니까?
위치 관리자를 사용하여 지오 펜스를 구현했습니다.
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLLocationAccuracyBest;
[locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];
-(void)TraceGeofenceLocation{
for (int k=0; k< [self.chGeofenceType count]; k++) {
NSString *chTracLati = [NSString stringWithFormat:@"%f",[[self.chGeofenceLatitudes objectAtIndex:k] doubleValue]];
NSString *chTracLong = [NSString stringWithFormat:@"%f",[[self.chGeofeceLongitudes objectAtIndex:k] doubleValue]];
NSString *chTracRadius = [NSString stringWithFormat:@"%f",[[self.chGeofenceRadius objectAtIndex:k] doubleValue]];
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(chTracLati.doubleValue, chTracLong.doubleValue);
if ([[self.chGeofenceType objectAtIndex:k] intValue] == 1) {
region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"Restricted"];
}
else if ([[self.chGeofenceType objectAtIndex:k] intValue] == 2){
region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"SafeZone"];
}
else{
region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"Curfew"];
}
[region setNotifyOnEntry:YES];
[region setNotifyOnExit:YES];
[locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];
}
}
추적
// 지리적 울타리로 여기
내가 만드는 오전 지역
내가 내 위임 테스트 여기보기에서 코드가로드 내가 객체를 생성 않았다 입력 메소드는 입력 할 영역이 있으면 입력합니다. ...
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
locationnew = locations.lastObject;
self.Latit=[NSString stringWithFormat:@"%f", locationnew.coordinate.latitude];
self.Longi=[NSString stringWithFormat:@"%f",locationnew.coordinate.longitude];
Speed = [[NSString stringWithFormat:@"%f",[locationnew speed]] floatValue];
NSLog(@"Speed :%f Latitude :%@ Longitude :%@",Speed,self.Latit,self.Longi);
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
if ([region.identifier isEqualToString:@"Restricted"]) {
[self sendNotificationtoServerwithtype:@"1"];
}
else if ([region.identifier isEqualToString:@"Curfew"]){
[self sendNotificationtoServerwithtype:@"3"];
}
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
if ([region.identifier isEqualToString:@"SafeZone"]){
[self sendNotificationtoServerwithtype:@"2"];
}
}
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if (state == CLRegionStateInside){
NSLog(@"is in target region");
}else{
NSLog(@"is out of target region");
}
}
내 대리자 메서드 업데이트 위치가 호출되고 난 콘솔, 에서 얻을 수 있지만, 지역의 지역, 출구에 입력하고 DetermineState 호출되지 않았다
아무도 나를 도와 줄 수 없어. 사전