ios - 删除 iOS 中的后台位置警报?

标签 ios swift location core-location

我正在编写一个跟踪用户位置的导航应用。

为了继续显示有关路线的通知(当手机锁定、接听电话等时)- 我还需要在应用程序处于后台时继续跟踪位置:(Capabilities>Background Modes >位置更新,locationManager.allowsBackgroundLocationUpdates = true)

我已经为这个问题苦苦挣扎了很长时间,也阅读了很多相关资料,但找不到我正在寻找的答案。 我已经实现了这两个选项:

选项 1 - 使用时请求

(locationManager.requestWhenInUseAuthorization()):

只要应用程序处于后台,每个应用程序顶部都会有一个额外的蓝色位置警告栏。

  1. 有没有办法删除这个横幅?或者只在很短的时间内得到它?再次-我 不能使用 locationManager.stopUpdatingLocation() - 因为我需要 他们在后台。

选项 2 - 始终请求(locationManager.requestAlwaysAuthorization()):

一段时间后,我的用户收到后台位置可怕的提示消息。示例:

‘APP' has been using your location in the background. Do you want to continue allowing this?

  1. 有没有办法删除这条消息? (以 Waze 为例 - 相同 权限,但我很确定我从来没有收到过这样的消息)
  2. 我可以停止在后台获取位置更新吗只有当 应用程序被终止? 并避免应用程序被唤醒(我实际上不想要这些位置)?我试着用 locationManager.stopUpdatingLocation() 终止应用程序时 - 开启 applicationWillTerminate(_ application: UIApplication)

似乎这两者不仅是糟糕的用户体验,会让用户望而却步,而且在其他基于位置的应用中也很少见。

我不知道我在这里遗漏了什么。

最佳答案

您提到的这两种机制都由操作系统来保护用户。它们不仅会提醒用户后台有应用程序正在检索其位置,还会提醒用户不再需要时可能会耗电。

没有办法避免这种情况,因此您应该根据您的应用程序的需要来决定哪种方式最适合。

例如,一些应用程序提供路线指示,这些应用程序的顶部往往有蓝色横幅(参见 Google Maps 甚至 Apple map )。

另一方面,其他一些应用程序有兴趣随时获取位置更新(例如健身应用程序或跟踪您所有运动的应用程序,请参阅 Moves)。在这种情况下,用户将收到一次关于此应用程序持续在后台使用其位置这一事实的警告,如果他们接受它,他们将不会再被打扰(iOS 8 及更高版本)。

以下是 Apple 工作人员提供的有关选项 2 的一些信息:

A few days after the app obtains the "always" authorization and starts using location services in the background, the user will be asked to confirm once again that they still want this app to track their location in the background.

There is no developer action that can be taken to avoid this confirmation if the app is obtaining users' location in the background.

Source: Apple Forums

Alert

Source: About privacy and Location Services in iOS 8 and later

关于ios - 删除 iOS 中的后台位置警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43514717/

相关文章:

android - 在 Google Map Android 中设置更新位置的时间

android - 如何使用网络在 android 中使用 Fused Location Provider 获取位置?

ios - 在 iOS 5.1.1/6.0 和 Xcode 4.5 上开发无许可证的应用程序

ios - 检查 UIImageView 中的图像不是占位符图像并附加到 UIImage 数组

iphone - UITableView 复选标记计数

ios - 使用 Swift + FMDB 打开和关闭数据库

ios - 如何使用Out @State 变量更新 SwiftUIView?和段错误问题

javascript - 如何在 iOS 的网页中设置选择?

ios - 从 scenekit 中的网络服务器加载 collada 文件

regex - 如何匹配 nginx 中无扩展名文件的位置?