Firemonkey,位置传感器在 iOS 的后台工作

Firemonkey, Location sensor work in background on iOS

我喜欢制作可以在后台模式下捕获我在 iPhone 上的位置的应用程序, 但我有一个问题:

应用程序无法请求表单许可 requestAlwaysAuthorization
基于这篇文章 http://delphiworlds.com/2016/02/location-sensor-work-in-the-background-on-ios-9/(演示应用程序不要求太多)如果我在 TiOSLocationSensor.DoStart: Boolean; 中将 System.iOS.SensorsFLocater.requestWhenInUseAuthorization 更改为 FLocater.requestAlwaysAuthorization 然后应用程序不要求任何权限。

当我允许 FLocater.requestWhenInUseAuthorizationFLocater.setAllowsBackgroundLocationUpdates(True); 时,应用程序在最小化时捕获位置,但在 StatusBar 中显示关于使用 LocationSensor 的蓝色大通知

但是我需要在隐藏模式下运行申请,我认为是授权方面的问题,但不知道如何解决。 (Delphi 10.2.2)

如有任何帮助,我将不胜感激

您只能在 iOS 11 或更高版本中使用 showsbackgroundlocationindicator 属性:

https://developer.apple.com/documentation/corelocation/cllocationmanager/2923541-showsbackgroundlocationindicator

为了使用它,您需要遵循与原始文章类似的方法,重新声明 CLLocation 管理器,添加方法:

procedure setShowsBackgroundLocationIndicator(showsBackgroundLocationIndicator: Boolean); cdecl;

..并重新声明 CLLocationManager 委托。在 TiOSLocationSensor.DoStart 中,您可以检查 iOS 11 并设置 属性,例如:

// Turn off the annoying blue indicator
if TOSVersion.Check(11) then
  FLocater.setShowsBackgroundLocationIndicator(False);