iOS: location not detected if Location Services are turned on while App was open

Dear All, 

I am facing the following scenario: 

  • App build.settings has NSLocationWhenInUseUsageDescription
  • In main.lua, there is Runtime:addEventListener( “location”, locationHandler )
  1. Ensure that Location Services is Off in Settings -> Privacy
  2. Install app, launch app which uses location
  3. Prompt occurs - Turn On Location Services to Allow “App” to Determine Your Location. Click on Settings -> enable Location Services 
  4. Hit Home and Launch the App again 

At this stage, the app does not detect the location or ask for permissions. However many times you close the app and relaunch, it does not. 

Only if we exit the app (kill it off), and relaunch it, that it detects the location. However, this would mean most new app users may never notice it, fail to use the app and uninstall. Also, Apple review team is rejecting this as a serious bug. 

Any suggestions or workarounds would be much appreciated! 

Cheers,

Anshuman

Found a workaround, in App Resume event, need to remove and add location listener again. 

 elseif ( event.type == "applicationResume" ) then if globals.appVerified then -- Remove location listener Runtime:removeEventListener( "location", locationHandler ) -- Activate location listener Runtime:addEventListener( "location", locationHandler )

This detects the fact that location settings have been enabled AFTER the app was started originally. 

Maybe the location event listener/handler should be able to detect this automatically? 

Your workaround isn’t a work around.  It’s the way this needs to be done.  Because Apple doesn’t like apps that exit, main.lua can be thought of as doing things only the first time the app is run… ever…  If you need to do things like check for facebook logins, initialize game center (could have a password change), etc.  those need to happen in the system events for started and resumed.  Location checks fall into that category.

Rob

Cheers Rob

Found a workaround, in App Resume event, need to remove and add location listener again. 

 elseif ( event.type == "applicationResume" ) then if globals.appVerified then -- Remove location listener Runtime:removeEventListener( "location", locationHandler ) -- Activate location listener Runtime:addEventListener( "location", locationHandler )

This detects the fact that location settings have been enabled AFTER the app was started originally. 

Maybe the location event listener/handler should be able to detect this automatically? 

Your workaround isn’t a work around.  It’s the way this needs to be done.  Because Apple doesn’t like apps that exit, main.lua can be thought of as doing things only the first time the app is run… ever…  If you need to do things like check for facebook logins, initialize game center (could have a password change), etc.  those need to happen in the system events for started and resumed.  Location checks fall into that category.

Rob

Cheers Rob