Learn To Use The Location Sensor In The Background With FireMonkey In Delphi 10 Berlin On IOS

location_sensor_iosDeveloper David Nottage proposes an interesting solution to a problem some of you might have noticed on FireMonkey when switching to iOS 9 or higher, in particular the Location Sensor stops working when the application is in background. The reason behind this behavior is that Apple introduced a new required property – allowBackgroundLocationUpdates to be set on CLLocationManager. Also you have to include location UIBackgroundModes in the project options. In order for the Location Sensor to work in the background you have to always pass True to requestWhenInUseAuthorization method. In order to make this change, you have to modify the implementation sections of the units: iOSapi.CoreLocation and System.iOS.Sensors and completely redeclare CLLocationManager here, and add the new methods for the property.

Here is some sample code:

If you want to always set the authorization for allowsBackgroundLocationUpdates not only when the sensor is active, you have to modify TiOSLocationSensor.DoStart method.

Head over and check out the demo for Using Location Sensor in Background for Delphi Berlin with FireMonkey.

Mirror: Download the background location sensor demo for Delphi on IOS.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Learn To Use The Location Sensor In The Background With FireMonkey In Delphi 10 Berlin On IOS by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.

Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Delphi 10 Berlin IOS Background App FireMonkey
Allow Apps To Run In Background Under FireMonkey In Delphi 10 Berlin On IOS

Developer David Nottage proposes a nice solution to keeping your applications to run in the background on iOS. On iOS...