sug*_*ron 5 cllocationmanager ios ios13
我的应用程序的核心功能是在后台模式下更新位置数据。在 iOS 13 中,当我们调用 时locationManager.requestAlwaysAuthorization(),系统会要求用户在变体'Never'、'Permit Once'和 中进行选择'When in use'。
如果用户授予'When in use'访问权限,我们的应用程序将只能在前台工作。
我无法理解的是:有时当应用程序进入后台并在一段时间后变为活动状态并再次进入后台时,iOS 13 会要求用户将位置访问权限更改为 'Always'

我的应用程序应该怎么做才能使 iOS 13 向用户显示此对话框?(我想这样做,当我的应用程序第一次进入后台时)
PS 我知道,我可以使用一些带有文本的自定义警报,例如“请转到系统设置并将此应用的位置访问权限调整为‘始终’模式”。但我需要知道,有没有办法使用上述“本机系统流程”?
谢谢!
@Claudio 的回答帮助我解决了我的问题。我发现它能够在获得'When in use'许可的情况下访问后台位置。为此,您必须设置locationManager.showsBackgroundLocationIndicator = true.
这是我的 locationManager 调整:
let locationManager = CLLocationManager()
if #available(iOS 9, *){
locationManager.allowsBackgroundLocationUpdates = true
}
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.headingFilter = kCLHeadingFilterNone
locationManager.pausesLocationUpdatesAutomatically = true
locationManager.activityType = .otherNavigation
if #available(iOS 11.0, *) {
locationManager.showsBackgroundLocationIndicator = true;
}
locationManager.delegate = self
locationManager.startMonitoringSignificantLocationChanges()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1155 次 |
| 最近记录: |