[Solved] Location events in the background

I’m developing an app that needs to keep track of a user’s location even when they’re doing something else on the device (e.g., talking on the phone). Natively, iOS supports requesting/receiving location events even when the app is running in the background. However, I’m concerned that Corona may not allow this.

With Corona, is there a way to declare that an app needs background location services?
[import]uid: 101071 topic_id: 20543 reply_id: 320543[/import]

Anything? Anyone? No one has tried this? [import]uid: 101071 topic_id: 20543 reply_id: 80892[/import]

Try this in build.settings.

[code]
settings =
{
iphone =
{
plist =
{
UIBackgroundModes = “location”
},
},

}
[/code] [import]uid: 13560 topic_id: 20543 reply_id: 80893[/import]

Thanks for the suggestion, Iano78. Unfortunately, when I add this build.settings file, it causes the app to crash on launch. No warnings or errors in the Corona console – but when launched on the iPhone, it presents the prompt to allow the app to use location, but then crashes immediately thereafter (before you have a chance to respond to the prompt).

Any other thoughts or ideas? [import]uid: 101071 topic_id: 20543 reply_id: 81345[/import]

Do you have your application to exits on suspend? [import]uid: 84637 topic_id: 20543 reply_id: 81357[/import]

No. Right now, I’m just using the GPS template app to test this capability. The only changes I made were to correct (replace) the deprecated function calls. Otherwise, it’s off-the-shelf. [import]uid: 101071 topic_id: 20543 reply_id: 81364[/import]

Add this to build.settings

UIApplicationExitsOnSuspend = false, [import]uid: 84637 topic_id: 20543 reply_id: 81367[/import]

Thanks Danny. I tried explicitly setting the UIApplicationExitsOnSuspend value as you suggested, but I’ve got the same result. When I launch the app (basically the GPS template) on the iPhone, it prompts for permission to use my location, but then immediately crashes. Here is my build.settings file:
[lua]settings =
{
iphone =
{
plist =
{
UIBackgroundModes = “location”,
UIApplicationExitsOnSuspend = false,
},
},
}[/lua]

Any thoughts? Again, without this file, the app launches fine – it just doesn’t keep receiving accurate location events in the background. [import]uid: 101071 topic_id: 20543 reply_id: 81515[/import]

UPDATE: I got the app to “work” by doing the following:

  • Loading on the iPhone
  • Launching it (it crashes as described before)
  • Going into settings and manually turning GPS on for the app (which is only visible here after at least one attempted launch)

The app will then launch. However, now that I have set UIBackgroundModes to “location”, the app exits on suspend – no matter what I set the UIApplicationExitsOnSuspend value to. I’ve tried setting it to false, then removing it entirely (the app wasn’t exiting on suspend before I had a build.settings file), and even setting it to true, but the result is now always the same. The app goes away if I launch another app or if I sleep the phone.

So, to summarize where I am, I can do either of the following:

  1. Allow the app to stay resident when put in the background (but GPS events stop flowing)
  2. Theoretically capture GPS events in the background, but the app’s terminating on suspend makes this useless.

Any help would be MUCH appreciated – as this capability is a show-stopper for the app I’m building. Thanks! [import]uid: 101071 topic_id: 20543 reply_id: 81720[/import]

Send what you have to danny [at] anscamobile [dot] com

and i will take a look :wink: [import]uid: 84637 topic_id: 20543 reply_id: 81723[/import]

Done. I really appreciate your help – and look forward to your feedback. [import]uid: 101071 topic_id: 20543 reply_id: 81726[/import]

I took your sample file and modified the build.settings a little.

This worked successfully for me :

[code]
settings =
{
iphone =
{
plist =
{
UIBackgroundModes = {
“location”,
},
UIApplicationExitsOnSuspend = false,

CFBundleIconFile = “Icon.png”,
CFBundleIconFiles = {
“Icon.png”,
“Icon@2x.png”,
“Icon-72.png”,
},
},
},
}
[/code] [import]uid: 84637 topic_id: 20543 reply_id: 81967[/import]

This worked!! Thanks Danny. It seems that the only real difference in your build.settings file is the curly braces around the “location” in UIBackgroundModes – which makes sense, since this is intended to be a list of services.

Again, many many thanks! [import]uid: 101071 topic_id: 20543 reply_id: 81980[/import]

No problem, glad to help [import]uid: 84637 topic_id: 20543 reply_id: 81981[/import]

Hey Curjo,

have you actually managed to get this fully working now? And if you set the app to do something at a specific location it wakes up?

Just interested to know as I’m looking to do something similar.

Thanks
Gary [import]uid: 7334 topic_id: 20543 reply_id: 83942[/import]

Hi Gary:

Yes, this feature is fully working – but so far, I don’t need the ability for the app to wake up at a certain location, so I haven’t tried that (yet). What I have tested is that it keeps capturing GPS data when other apps are running in the foreground and/or when the screen goes black (sleep).

Cheers,

  • Curtis [import]uid: 101071 topic_id: 20543 reply_id: 83991[/import]

We have an app that is performing GPS calls in the background but when the app is suspended, after about 5 minutes the location services stop working. This is consistent in iOS and Android.
These functions are called from another file that is not part of any scene.

Has anyone else encountered that error? [import]uid: 9046 topic_id: 20543 reply_id: 130153[/import]

We have an app that is performing GPS calls in the background but when the app is suspended, after about 5 minutes the location services stop working. This is consistent in iOS and Android.
These functions are called from another file that is not part of any scene.

Has anyone else encountered that error? [import]uid: 9046 topic_id: 20543 reply_id: 130153[/import]

This feature seems like just what I am looking for…

But is there an equivalent way to do the same in android?

Prevent suspension or running a background process to carry on reporting GPS location is what I need. [import]uid: 192742 topic_id: 20543 reply_id: 130291[/import]

This feature seems like just what I am looking for…

But is there an equivalent way to do the same in android?

Prevent suspension or running a background process to carry on reporting GPS location is what I need. [import]uid: 192742 topic_id: 20543 reply_id: 130291[/import]