gpt4 book ai didi

ios - iOS GPS位置跟踪

转载 作者:行者123 更新时间:2023-12-01 18:45:53 25 4
gpt4 key购买 nike

我在Xcode上使用Objective C编程,当我的应用进入后台时似乎出现了问题。我有一个GPS跟踪应用程序,当用户运行该应用程序时它运行良好,但是当它在后台运行时,GPS不会逐步跟踪用户位置。它会暂停,然后在应用程序重新打开时自动找到该位置,但是我希望GPS一直运行,因此它不会像附件中的图片一样“走开” 1

我已经在后台模式下打开了位置更新和后台抓取功能。

   #pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations: (NSArray *)locations
{

if (!self.timerPause) {
for (CLLocation *newLocation in locations) {

NSDate *eventDate = newLocation.timestamp;

NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];

if (fabs(howRecent) < 10.0 && newLocation.horizontalAccuracy < 20)

其他代码
     if (self.locationManager == nil) {
self.locationManager = [[CLLocationManager alloc] init];
}
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.activityType = CLActivityTypeAutomotiveNavigation;
self.locationManager.distanceFilter = 10; // meters
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];

最佳答案

locationManager.allowsBackgroundLocationUpdates = YES;

将其添加到您设置了位置管理器的位置。它应该工作:)

关于ios - iOS GPS位置跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36050821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com