3

私はアプリが殺されたり終了したときに、緯度と経度を取得する必要がある機能を1つ持っています。歩行中に場所が更新されず、アプリが殺されたとき

車に乗っているときに、アプリが殺されたり終了したりすると、緯度と経度が表示されています。

しかし、私が数分間歩き始めたとき、私はアプリの殺された/終了した緯度と経度を取得していません。

以下は私の論理です。上記

+ (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

から呼び出す午前AppDelegate.mファイルで、私は

- (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メートルは歩くのに長い道のりであるため、徒歩では "重要な場所の変更"が発生する可能性はありません。

+0

しかし、あなたが正常に歩いていても常に位置を更新している "Zenly"のような他のアプリがあります。 – Nirav

+0

重要な場所を使用しないでください。 GPSを使用します。リンゴごと:「重要な変更を行うロケーションサービスは、500メートル以上など、デバイスの場所に大きな変化があった場合にのみ、アップデートを提供します。 https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html –

+0

GPSを使用します。あなたは私に例を示すことができますか? – Nirav

関連する問題