[英]Location not updating while walking, when app is killed
我有一個功能,當應用程序被殺或終止時,我應該獲得位置的緯度和經度。
當我騎車時,我會在應用被殺/終止時獲得經緯度。
但是當我開始走幾分鍾然后我就沒有得到應用程序被殺/終止的經度和經度。
以下是我的邏輯。
+ (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調用的Locationmanager類
在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;
}
有小費嗎 ?? 謝謝...
您要求“重要位置變更”。 我對API和相關區域監測的研究和經驗是,由於它使用蜂窩塔代替GPS,因此分辨率非常粗糙。 我們嘗試在30米處使用它並且它不穩定。 我們把它撞到了100米,它更好。 似乎大多數人建議200米用於區域監測,因此步行不太可能在一段時間內引發“重大位置變化”並不奇怪,因為在幾分鍾內行走200米是很長的路。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.