后台位置更新在主项目中停止工作

问题描述 投票:0回答:1

我有一个使用后台位置来跟踪用户运行活动的 Pod。当我直接使用 pod 项目时,它会在后台进行跟踪,没有任何问题,但是当我将 pod 安装到另一个项目中时,后台位置会持续大约 50 秒,直到停止获取更新。我在 Xcode 中使用相同的配置和相同的权限。

.plist 文件中的位置权限:

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>The application needs to know your location to locate your photos and each point of the race in live.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>The application needs to know your location to locate each point of the race in live.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>The application needs to know your location when uploading the photo to locate it at each point of the race.</string>

我的位置管理器配置:

self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.activityType = .fitness
self.locationManager.requestAlwaysAuthorization()
self.locationManager.pausesLocationUpdatesAutomatically = false
self.locationManager.showsBackgroundLocationIndicator = true
self.locationManager.allowsBackgroundLocationUpdates = true

我在后台模式下激活了位置更新。

ios swift swiftui
1个回答
0
投票

我终于找到罪魁祸首了。我在位置活动开始之前在屏幕上使用 Lottie 动画,我发现如果我在推到下一个屏幕时隐藏 Lottie 视图,则背景位置工作正常。也许 Lottie 库有某种进程会在一段时间后杀死应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.