Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Background and LocationSensor



Permlink Replies: 3 - Last Post: Feb 26, 2016 6:14 PM Last Post By: Dave Nottage
John vd Waeter

Posts: 34
Registered: 11/9/02
Background and LocationSensor
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2016 5:09 AM
Hi All,
Has someone managed to keep the locationsensor working in the background?

I have a form with a TLocationsensor on it, and a button.
The button sets the locationsensor's Active property to true;
I can see the locationsensor on my iphone 4s (ios 9.02) turn on.

On the project options page, I have requested the UIBackgroundmode "location"

But now when I background the app by pressing the home button, I see the location-indicator of the iPhone disappear after about 10 seconds.
My program got suspended instead of running in the background.

There are no User Interface updates.

Am I missing something?

Using Seattle

tia!
John

Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Background and LocationSensor
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2016 7:32 AM   in response to: John vd Waeter in response to: John vd Waeter
John vd Waeter wrote:

But now when I background the app by pressing the home button, I see the location-indicator of the iPhone disappear
after about 10 seconds. My program got suspended instead of running in the background.

There are no User Interface updates.

Am I missing something?

The Delphi iOS code is missing a call to requestAlwaysAuthorization. Instead, it calls requestWhenInUseAuthorization
which means your app will stop receiving updates shortly after going into the background. Also, as of iOS9, there's a
new property called allowsBackgroundLocationUpdates which must be set to True. This property is not declared on the
CLLocationManager interface in Delphi, so it needs to be added.

This is a topic that interests me, so sometime in the next day or so, I'll take a deeper look at how much work this
will involve, preferably without changing the original Delphi source too much. Alternatively, the DPF library:

https://sourceforge.net/projects/dpfdelphiios/

May have done all of this already.

--
Dave Nottage [TeamB]
Delphi Worlds blog: http://delphi.radsoft.com.au/blog
John vd Waeter

Posts: 34
Registered: 11/9/02
Re: Background and LocationSensor
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2016 10:56 AM   in response to: Dave Nottage in response to: Dave Nottage
Hi Dave, thanks for responding!

The Delphi iOS code is missing a call to requestAlwaysAuthorization. Instead, it calls requestWhenInUseAuthorization
which means your app will stop receiving updates shortly after going into the background. Also, as of iOS9, there's a
new property called allowsBackgroundLocationUpdates which must be set to True. This property is not declared on the
CLLocationManager interface in Delphi, so it needs to be added.

This is a topic that interests me, so sometime in the next day or so, I'll take a deeper look at how much work this
will involve, preferably without changing the original Delphi source too much. Alternatively, the DPF library:

Ok, thanks a lot for this confirmation! I was sure it worked XE8 / iOS7/8. But not many of my users appear to have used the app in the background. There were never complaints, until recently. But in the meantime my development env changed to DX Seattle, MacOS, XCODE and pa server changed, my phone has iOS 9.2 now, so it was kinda hard to figure out where it went wrong...

https://sourceforge.net/projects/dpfdelphiios/

May have done all of this already.

I tried, but couldn't find a component in this set that would replace the LocationSensor. Should there be?

Thanks again, and please keep us posted if you find some workaround!

Cheers,
John
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Background and LocationSensor
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2016 6:14 PM   in response to: John vd Waeter in response to: John vd Waeter
John vd Waeter wrote:

Thanks again, and please keep us posted if you find some workaround!

I've published this post:

http://delphi.radsoft.com.au/2016/02/making-the-location-sensor-work-in-the-background-on-ios-9/

I also have a test project constructed, but I'm heading out for a while, so I'll update it later.

--
Dave Nottage [TeamB]
Delphi Worlds blog: http://delphi.radsoft.com.au/blog
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02