1. 程式人生 > >ios LocationSensor 後臺運行

ios LocationSensor 後臺運行

ati span ios clas then ras als ear learn

設置好技術分享,LocationSensor.active := true。

當按home鍵或黑屏後,程序將立馬掛起。LocationSensorLocationChanged事件也不會響應。

有人說要兩三秒才掛起,到我這卻是立馬,不知為啥。

在網上知道的解決方案:http://www.fmxexpress.com/learn-to-use-the-location-sensor-in-the-background-with-firemonkey-in-delphi-10-berlin-on-ios/

經測試後,發現它並不能完全做到後臺一直運行。一般運行十來分鐘就停止了。

具體解決方案:在上述網址基礎(FLocater.setAllowsBackgroundLocationUpdates(True);

)上,還需要加上

FLocater.setPausesLocationUpdatesAutomatically(False);

也就是

if TOSVersion.Check(9) and (FLocater <> nil) then

begin {$IF Defined(BACKGROUNDUPDATES) and Defined(CPUARM64)} // for some reason, this function crashes in 32-bit FLocater.requestAlwaysAuthorization; FLocater.setAllowsBackgroundLocationUpdates(True);
FLocater.setPausesLocationUpdatesAutomatically(False); {$ENDIF} end;

ios LocationSensor 後臺運行