2015-01-01 4 views
0

지오 펜싱으로 앱을 만들고 있습니다. 나는 here을 읽고 앱을 만들었습니다. 그것은 추락하지는 않지만 감시 구역으로 들어가면 반응하지도 않습니다. "시작된 모니터링"에서 로그 아웃하지만 내 * .GPX 파일을 선택하면 반응하지 않습니다. 나는 00.0 내 실제 좌표를 교체 한지오 펜싱이 작동하지 않습니다.

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<gpx 
xmlns="http://www.topografix.com/GPX/1/1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" 
version="1.1" 
creator="gpx-poi.com"> 
<wpt lat="00.0" lon="00.0"> 
<time>2015-01-01T14:45:02Z</time> 
</wpt> 
</gpx> 

:

@interface myViewController() { 
CLLocationManager *locationManager; 
} 

@end 

@implementation RegisterViewController 

@synthesize GeoFences; 

- (void)viewDidLoad { 
[super viewDidLoad]; 

// Initalize locationManager 
locationManager = [[CLLocationManager alloc] init]; 
} 

- (IBAction)getLocation:(id)sender { 
// Start monitoring 
// Create a home NSDictionary 
NSDictionary *myDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"23123124arevar", @"title", @"00.0", @"latitude", @"00.0", @"longitude", @"100", @"radius", nil]; 
NSMutableArray *regions = [[NSMutableArray alloc] init]; 
CLRegion *region = [self mapDictionaryToRegion:myDictionary]; 
[regions insertObject:region atIndex:0]; 
NSLog(@"Count: %lu", [regions count]); 
[self startMonitoringRegions:regions]; 
} 

- (void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

- (CLRegion*)mapDictionaryToRegion:(NSDictionary*)dictionary 
{ 
NSString *title = [dictionary valueForKey:@"title"]; 

CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue]; 
CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue]; 
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude); 

CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue]; 

return [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate 
               radius:regionRadius 
              identifier:title]; 
} 

-(void)startMonitoringRegions:(NSMutableArray *)array { 
for (CLRegion *GeoFence in array) 
{ 
    NSLog(@"Started monitoring"); 
    [locationManager startMonitoringForRegion:GeoFence]; 
} 
} 

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
{ 
NSLog(@"Exited Region - %@", region.identifier); 
// post a notification 
} 

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region 
{ 
NSLog(@"Exited Region - %@", region.identifier); 
// post a notification 
} 

@end 

가 여기 내 *의 .GPX 파일입니다 : 이것은 내의 ViewController 코드입니다.

누군가 내게 * .GPX 영역을 입력 할 때 아무런 이유없이이 작업을 수행 할 수 있습니까? 또한 더 적절한 식별자를 만들려면 어떻게해야합니까?

감사합니다. 에릭

답변

0

나는 당신이 당신의 뷰 컨트롤러에을 locationManager 대리자를 설정하는 것을 잊었다 생각 :

locationManager.delegate = self; 

은을 locationManager를 생성 한 후있는 viewDidLoad이 넣습니다.

오류를 감지하려면 monitoringDidFailForRegion도 구현해야합니다. startMonitoring을 호출한다고해서 실제로 시작된다는 보장은 없습니다. 여러 가지 이유로 실패 할 수 있습니다.

+0

우수한 작품입니다. 몇 가지 질문 만하고 didFailToStartMonitoring 메소드를 볼 수 없습니까? 또한 앱이 실행되고 있지 않으면이 메소드가 실행됩니까? 앱이 실행 중이 지 않고 didEnterRegion 내부에 UIAlertView를 만든 경우 어떻게됩니까? – Erik

+0

미안하지만, 나는 그걸 기억하려고했다. 이 메서드는 실제로 DidFailForRegion을 모니터링합니다. 그것은 위임 방법입니다. 앱이 지역을 입력 할 때 아직 실행 중이 아닌 경우 iOS가 앱을 시작합니다. 그러나 didEnterRegion 메서드가이 경우에 실행되는지 여부를 지금은 기억할 수 없습니다. –

+0

나는 그걸 가지고 놀았는데, 만약 당신이 애플 리케이션을 닫기 전에 태스크 매니저에서 그것을 스 와이프하지 않으면 NSLog가 영역을 떠날 때 나 떠날 것이지만, 앱이 열리기 전에는 UIAlertViews 나 유사한 것을 만들지 않을 것이다. 시뮬레이터로 조금 열심히했기 때문에 앱을 닫으면 확인하지 못했습니다.하지만 결과는 같을 것이라고 생각하십니까? 디버깅하는 동안 작업을 멈추게 할 수 없어, 내 iPhone에서 시도 할 것입니다. 그러나 사용자가 버튼과 같이 지역 내에 있는지 어떻게 확인할 수 있습니까? BOOL을 didEnterRegion에 연결하거나 더 나은 방법일까요? – Erik

관련 문제