3

앱이 죽거나 종료 될 때 위치의 위도와 경도를 가져야하는 기능이 하나 있습니다.걷는 중 앱이 죽을 때 위치가 업데이트되지 않음

차량을 탈 때 앱이 죽거나 종료 될 때 위도와 경도가 표시됩니다.

하지만 몇 분 동안 걷기 시작하면 앱에서 위도와 경도가 사라지거나 종료됩니다.

다음은 제 논리입니다.

+ (CLLocationManager *)sharedLocationManager { 
static CLLocationManager *_locationManager; 

@synchronized(self) { 
    if (_locationManager == nil) { 
     _locationManager = [[CLLocationManager alloc] init]; 
     _locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; 
     _locationManager.allowsBackgroundLocationUpdates = YES; 
     _locationManager.pausesLocationUpdatesAutomatically = NO; 
     _locationManager.activityType = CLActivityTypeOther; 
     _locationManager.distanceFilter = kCLDistanceFilterNone; 
    } 
} 
     return _locationManager; 
} 

- (id)init { 
    if (self==[super init]) { 
    //Get the share model and also initialize myLocationArray 
    self.shareModel = [LocationShareModel sharedModel]; 
    self.shareModel.myLocationArray = [[NSMutableArray alloc]init]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; 
} 
    return self; 
} 

-(void)applicationEnterBackground{ 
CLLocationManager *locationManager = [LocationTracker sharedLocationManager]; 
locationManager.delegate = self; 
[locationManager stopMonitoringSignificantLocationChanges]; 

if(IS_OS_8_OR_LATER) { 
    [locationManager requestAlwaysAuthorization]; 
} 
[locationManager startMonitoringSignificantLocationChanges]; 

//Use the BackgroundTaskManager to manage all the background Task 
self.shareModel.bgTask = [BackgroundTaskManager sharedBackgroundTaskManager]; 
[self.shareModel.bgTask beginNewBackgroundTask]; 
} 

위 내가

그리고 AppDelegate.m 파일에

AppDelegate에이, 내가

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

UIAlertView * alert; 

//We have to make sure that the Background App Refresh is enable for the Location updates to work in the background. 
if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusDenied){ 

    alert = [[UIAlertView alloc]initWithTitle:@"" 
             message:@"The app doesn't work without the Background App Refresh enabled. To turn it on, go to Settings > General > Background App Refresh" 
            delegate:nil 
          cancelButtonTitle:@"Ok" 
          otherButtonTitles:nil, nil]; 
    [alert show]; 

}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusRestricted){ 

    alert = [[UIAlertView alloc]initWithTitle:@"" 
             message:@"The functions of this app are limited because the Background App Refresh is disable." 
            delegate:nil 
          cancelButtonTitle:@"Ok" 
          otherButtonTitles:nil, nil]; 
    [alert show]; 

} else{ 
    self.locationTracker = [[LocationTracker alloc]init]; 
    [self.locationTracker startLocationTracking]; 

     //Send the best location to server every 60 seconds 
     //You may adjust the time interval depends on the need of your app. 
    if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) { 

     NSTimeInterval time = 10; 
     self.locationUpdateTimer = 
     [NSTimer scheduledTimerWithTimeInterval:time 
             target:self 
             selector:@selector(updateLocation) 
             userInfo:nil 
             repeats:YES]; 
    } 


} 

return YES; 
} 

아래 어떤 조언처럼 쓴에서 전화하고 내을 locationManager 클래스입니다 ?? 감사합니다 ...

+0

배경 모드에서 관련 변경 사항을 수행 했습니까? –

+0

@ReshmiMajumder : 예, 위치 및 배경 가져 오기를위한 백그라운드 모드를 활성화했습니다 – Nirav

+0

걷는 동안 위치를 업데이트하려면 인터넷 또는 3G가 필요합니까? @ ReshmiMajumder – Nirav

답변

0

"SignificantLocationChanges"를 요청합니다. API 및 관련된 지역 모니터링에 대한 나의 연구 및 경험은 GPS 대신 셀 타워를 사용하기 때문에 해상도가 매우 거칠다는 것입니다. 우리는 30 미터에서 그것을 사용하려고 시도했고 그것은 이상했다. 우리는 그것을 100 미터까지 부딪 쳤고 더 좋았습니다. 대부분의 사람들은 지역 모니터링을 위해 200 미터를 제안하는 것으로 보입니다. 놀랍지도 않은 일이지만 200 미터는 먼 거리에서 걸을 수있는 길이기 때문에 걷는 것이 "SignificantLocationChange"를 유발할 가능성은 없습니다.

+0

그러나 정상적으로 걸어도 위치를 계속 업데이트하는 "Zenly"와 같은 다른 앱이 있습니다. – Nirav

+0

중요한 위치를 사용하지 마십시오. GPS를 사용하십시오. 사과당 : "중요한 변경 위치 서비스는 500 미터 이상과 같이 장치의 위치가 크게 변경된 경우에만 업데이트를 제공합니다." https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html –

+0

GPS를 사용하지만 어떻게해야합니까? 나 한테 보여 줄 수있어? – Nirav

관련 문제