2014-01-03 3 views
0

나는이 두통 질문으로 웹에서 오랫동안 실행 해 왔기 때문에 여기에서 질문을하기로했습니다. 사용자가 위치를받은 마지막 시간 (반복적으로)에서 X 미터를 이동할 때 알림을 수신하는 기능을 만들려고합니다. 위치를 수신 할 때마다 내 서버로 푸시합니다. CLLocationManager으로 설정했지만 앱이 포 그라운드/백그라운드에있을 때만 작동하지만 앱이 비활성 상태 인 경우에는 작동하지 않습니다 (사용자가 홈 키를 두 번 클릭했을 때 앱을 슬라이드하여 제거함). didFinishLaunchingWithOptions:[locationManager startUpdatingLocation]을 사용해 보았습니다. 전과 마찬가지로 [locationManager startUpdatingLocation]을 사용해 보았습니다. 그러나 처음 위치를 수신 할 때 온라인으로 이해하면 지오 펜스 만 앱이 비활성 상태 일 때 알림을받을 수 있기 때문에 지역 모니터를 사용하기 시작합니다. app registers for location updatesrequired Background Modes을 추가했습니다. 도 Application does not run in the backgroundNO을 추가하려고 시도했습니다.CLLocationManager가 X 미터마다 알림

서버를 보면 응용 프로그램이 활성화되어있을 때 (UIApplicationState == 0)/background (UIApplicationState == 2), UIApplicationState == 1 (비활성)이 아니라면 알림을받습니다.

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
CLLocation *lastLocation = locations.lastObject; 
[self saveToServer]; 
[self.locationManager stopUpdatingLocation]; 
[self.locationManager startMonitoringForRegion:[[CLCircularRegion alloc] initWithCenter:lastLocation.coordinate radius:20 identifier:@"20"]]; 
} 

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
{ 

} 

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region 
{ 
CLLocation *lastLocation = manager.location; 
if(lastLocation) 
{ 
    [self saveToServer]; 

    [self.locationManager startMonitoringForRegion:[[CLCircularRegion alloc] initWithCenter:lastLocation.coordinate radius:20 identifier:@"20"]]; 
} 
} 

- (CLLocationManager *)locationManager 
{ 
if (_locationManager != nil) { 
    return _locationManager; 
} 

_locationManager = [[CLLocationManager alloc] init]; 
[_locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters]; 
_locationManager.distanceFilter = 20; 
_locationManager.pausesLocationUpdatesAutomatically = NO; 
[_locationManager setDelegate:self]; 
return _locationManager; 
} 

감사합니다 : 이 참조 내 코드입니다.

답변

0

iOS 7은 멀티 태스킹 스위처에서 수동으로 종료 된 앱의 백그라운드 서비스를 다시 시작하지 않습니다. 사용자는 위치 서비스를 재개하기 위해 홈 화면의 아이콘을 탭하여 앱을 수동으로 실행해야합니다.

WWDC 2013 세션보기 307 : https://developer.apple.com/wwdc/videos/

+0

그래서 불가능합니다. Foursquare 나 Facebook은 어떻게합니까? – user2558461

관련 문제