So how to get GPS updates when app is in background?

Well, after a month or so of delving into Corona and learning the ropes, I discovered that there seems not to be a way to make an SDK (maybe even Enterprise and Cards?) app to catch location events when in background. Saw a thread that can’t find anymore where it seems there is no way nor roadmap to get background functionalities.

That’s kind of a deal breaker (I know I know, I should have done my research one month ago …) for the kind of apps I plan to implement. Basically they are various types of tourist apps, and I don’t want tourists to keep their smartphone in their hand and staring at it when they should be enjoying the vistas.
Ideally they would just go around, smartphone in their pocket and probably even locked, and the app would still receive the location events. When near to a specific point of interest or other trigger, the app would do something: vibrate the phone, play a sound, etc …

I am trying to find a way - any way - to supplement the simplicity of Corona to this very central functionality. I saw non-corona apps such as Zombies, run! and the like which do keep track of user movement and notify when it walked a certain distance. 
I am not sure how they did it in native code so I can’t easily trace a parallel. I guess that in Corona there’d be “something” running all the time and connected to the app that generates some local notifications (can local notifications even be shared?), or some other kind of communication with the app, which means try to implement some message/state passing mechanism that does not clash with the OS enforced sandboxing of apps. Sone “mystery component” would be the background part evolving the state of the user experience based on various constraints (the “producer”) and issues a notification that when tapped wakes the corona app (the “consumer”). Only problem - apart from feasibility - is that I see a big chunk of functionalities that need to go into the native code / service part, which kind defeats the purpose.

Ok, bringing the rambling to a close - any way to keep experimenting with Corona re. this, or should I try different frameworks / solutions for this specific need?

thanks in advance for pointers, even better if some proof of concept is available and could be shared …

Corona SDK does not support receiving events while in the background.

Rob

Hi Rob, what about Enterprise or Cards? Any chance to do it while keeping the amount of native code to a minimum? (maybe there’s something out there already?)

We would be very interested to know the answer to that question as we are also building tourism app with Corona. Building the notification with Enterprise (natively) would not be a problem for us, but a pointer to the recipe would be greatly appreciated.

The part of Corona SDK that renders the UI is not background safe. We expect an active app before we render anything. That said, you _ might _ be able to use Corona Enterprise or CoronaCards to collect the GPS data while backgrounded but you can’t send it to the Lua engine until the app is on screen and we are updating the display.

Rob

Corona SDK does not support receiving events while in the background.

Rob

Hi Rob, what about Enterprise or Cards? Any chance to do it while keeping the amount of native code to a minimum? (maybe there’s something out there already?)

We would be very interested to know the answer to that question as we are also building tourism app with Corona. Building the notification with Enterprise (natively) would not be a problem for us, but a pointer to the recipe would be greatly appreciated.

The part of Corona SDK that renders the UI is not background safe. We expect an active app before we render anything. That said, you _ might _ be able to use Corona Enterprise or CoronaCards to collect the GPS data while backgrounded but you can’t send it to the Lua engine until the app is on screen and we are updating the display.

Rob

I’m on the hunt for an answer and found this post so I wanted to chime in for some feedback from you guys. It seems like the background services for GPS location no longer works using Corona built towards an iOS 9 device. I’ve tried most scenarios I’ve found, nothing works. Not even the example code (modified build settings of course).

It seems to all point towards this: http://stackoverflow.com/questions/30808192/allowsbackgroundlocationupdates-in-cllocationmanager-in-ios9

Anyone else having issues like this?

My app has been in the market for a long time running just fine, even as recent an September 2015 with an update (pre iOS 9).

Do you have this in your build.settings?

NSLocationWhenInUseUsageDescription = “This app uses maps and GPS when active to …”,

I don’t know how much that Apple wants you running the GPS in the background any more.

Rob

Yep, have that. And the app I’m talking about is a top 100 app and been published for two years. Apple is fine with the app - it’s the Corona build to iOS compatibility. 

Try to get the sample project to run in the background (after making the neccessary adjustments to build.settings) and you’ll see what I mean. 

Can you try including this key in your build.settings:   NSLocationAlwaysUsageDescription

It takes a string saying why you always want to use the GPS.

Rob

Hey Rob, 

Yeah - I’ve tried both strings - by themselves, and together, nada.

NSLocationWhenInUseUsageDescription = “blah blah blah”,

NSLocationAlwaysUsageDescription = “blah blah blah blah.”,

I’m at a total loss here.

I know Corona doesn’t officially support running BG services in the background but it’ been working fine until iOS 9 and I really, really think it has to do with the way is access core services.

From:http://stackoverflow.com/questions/32758125/ios9-not-tracking-location-while-in-background

This new property is explained in the WWDC session “What’s New in Core Location”.

The default value is NO if you link against iOS 9.

If your app uses location in the background (without showing the blue status bar) you have to set allowsBackgroundLocationUpdates to YES in addition to setting the background mode capability in Info.plist. Otherwise location updates are only delivered in foreground. The advantage is that you can now have location managers with background location updates and other location managers with only foreground location updates in the same app. You can also reset the value to NO to change the behavior.

I know if this isn’t fixed, it will be a deal killer for me and anyone else using bg services in Corona and publishing an update to > iOS 9

Rob, any update on this? I’m still waiting on a response from Corona.

First of all, it’s the weekend. I’m not going to get any information over the weekend. Secondly, our official response is Corona SDK does not support backgrounding apps. As you said, there’s not “official” support. There is no “kind of supports” either.

Apple made changes in iOS 9. While they allow backgrounded nav apps, they discourage it to save battery life and they want people to know their movements are being measured while backgrounding.

We are having a discussion (during normal business hours) about it. I wouldn’t expect an answer for a few days.

Rob

Just to give me some ammo to go to bat for you, can you provide the links to your app store entries for this app?

Rob

Hi Rob, sure. You can find the iOS and Android  app downloads at http://chirpgps.com

It is #44 on top grossing travel apps again today -

Thanks.

Richard

Can you post your build.settings please?

Thanks

Rob

settings =

{

plugins =

   {

      [“plugin.facebook.v4”] =

{

publisherId = “com.coronalabs”

},

      [“plugin.OneSignal”] =

   {

       publisherId = “com.onesignal”,

   },

   [“plugin.google.play.services”] =

   {

publisherId = “com.coronalabs”,

supportedPlatforms = { android=true, [“android-kindle”]=true },

   },

   },

orientation = {

default = “portrait”, 

supported = {“portrait”},

},

  android =

        {

        versionCode = “5”,

        installLocation=“preferExternal”,

        usesPermissions =

{

“android.permission.INTERNET”,

       “android.permission.ACCESS_FINE_LOCATION”,

“android.permission.ACCESS_COARSE_LOCATION”,

       “android.permission.WRITE_EXTERNAL_STORAGE”,

       “android.permission.VIBRATE”,

       “android.permission.GET_ACCOUNTS”,

“android.permission.RECEIVE_BOOT_COMPLETED”,

“com.google.android.c2dm.permission.RECEIVE”,

“.permission.C2D_MESSAGE”,

},

intentFilters =

     {

        {

           label = “nothing.nothing.com”,

           actions = { “android.intent.action.VIEW” },

           categories =

           {

              “android.intent.category.DEFAULT”,

              “android.intent.category.BROWSABLE”,

           },

           data = { scheme = “test” },

        }

     },

        },

iphone =

{

plist =

{

UIBackgroundModes = {“location”, “fetch”, “remote-notification” },

            NSLocationUsageDescription = “Just some text.”,

            NSLocationWhenInUseUsageDescription = “Just some text.”,

            NSLocationAlwaysUsageDescription = “Just some text.”,

            CFBundleIconFile = “Icon.png”,

       CFBundleIconFiles = {

          “Icon.png”,

                “Icon@2x.png”,

                “Icon-60.png”,

                “Icon-60@2x.png”,

                “Icon-60@3x.png”,

                “Icon-72.png”,

                “Icon-72@2x.png”,

                “Icon-76.png”,

       },

       UILaunchImages = {

        {  – iPhone 6 Plus LandscapeLeft

                    [“UILaunchImageMinimumOSVersion”] = “8.0”,

                    [“UILaunchImageName”] = “Default-Landscape-736h”,

                    [“UILaunchImageOrientation”] = “LandscapeLeft”,

                    [“UILaunchImageSize”] = “{414, 736}”

                },

                {  – iPhone 6 Plus LandscapeRight

                    [“UILaunchImageMinimumOSVersion”] = “8.0”,

                    [“UILaunchImageName”] = “Default-Landscape-736h”,

                    [“UILaunchImageOrientation”] = “LandscapeRight”,

                    [“UILaunchImageSize”] = “{414, 736}”

                },

       },

       NSAppTransportSecurity =

{

NSAllowsArbitraryLoads = true

},

       UIAppFonts = 

{

“Avenir-Book.ttf”

},

       FacebookAppID = “777777777777”,

       

UIApplicationExitsOnSuspend = false,

CFBundleURLTypes =

{

{

CFBundleURLSchemes =

{

“77777777777777”,

“testing”

}

}

},

       UIPrerenderedIcon = true,

CFBundleDisplayName=“Appname”,

CFBundleIdentifier=“app.name.here”,

CFBundleVersion=“10.2”

},

}

}