[英]iOS update location after kill app from Background
In my project, I want to track user location. 在我的项目中,我想跟踪用户位置。 For that i want to update user current location based on location accuracy(for High-> 15 min and Low -> 1 hour). 为此,我想基于位置精度(高-> 15分钟和低-> 1小时)更新用户当前位置。 When application run or in background than I can update location but after kill application from background, can't update location. 当应用程序运行或在后台运行时,我可以更新位置,但是从后台终止应用程序后,无法更新位置。 I used timer to call it but after kill app(from background), it's not work. 我使用计时器来调用它,但是在杀死应用程序(从后台)后,它不起作用。
So now what i do to update location based on location accuracy if user not run app in background also. 因此,如果用户也未在后台运行应用程序,那么我现在将根据位置准确性来更新位置。
Please give any suggestion. 请提出任何建议。
CoreLocation has 2 permisson: CoreLocation具有2个许可:
Use the second one, that's what GPS use for instance. 使用第二个,例如GPS使用的那个。 But if you kill the app that is a going to stop updating location. 但是,如果您终止了该应用程序,将停止更新位置。
You need to add the NSLocationAlwaysUsage keys to your apps info.plist and then request permission when you wish to start monitoring. 您需要将NSLocationAlwaysUsage键添加到应用程序info.plist中,然后在希望开始监视时请求权限。
Make sure you give a good description of why you want to always monitor bc I feel that really helps conversion rates. 确保您对为什么要始终监视不列颠哥伦比亚省进行了很好的描述,我认为这确实有助于转换率。
locationManager = [[CLLocationManager alloc] init];
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
if(IS_OS_8_OR_LATER)
{
[locationManager requestWhenInUseAuthorization];
}
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; //whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
that code user location update only forground app running but not background run 该代码用户位置仅针对正在运行的地面应用程序进行更新,而不会针对后台运行情况进行更新
if(IS_OS_8_OR_LATER)
{
[locationManager requestWhenInUseAuthorization];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.