Location events in iOS

Hi all,

I need some help, I don’t understand why my app isn’t generating location events on iOS, or even on the xcode simulator. It also doesn’t ask for user permission, but it should, right?

It works on Android and windows simulator (even throws 3 events at once on startup).

I hope it’s not some obvious configuration issue, because I’ve checked the Location documentation multiple times. But help me out.

Summarized code. You can see I tried lowering the threshold for the first event, but it didn’t change anything:

----------------------------------------------------------------------------- -- Location routine ----------------------------------------------------------------------------- -- Setup location hardware system.setLocationAccuracy( 10 ); system.setLocationThreshold( 1 ); -- first event only -- Debug text (global) debugBox = display.newText({ -- the args }); -- Location event handler local debugCount = 0; local netCount = 0; local function locationHandler( locEvent ) -- Increase threshold after first event system.setLocationThreshold( 100 ); debugCount = debugCount + 1; if ( debugCount == 1 ) then debugBox.text = debugBox.text .. "location event\n"; if ( locEvent.errorCode ) then debugBox.text = debugBox.text .. locEvent.errorMessage; end end -- If no error if ( not locEvent.errorCode ) then if ( debugCount == 1 ) then debugBox.text = debugBox.text .. "no error\n"; end -- some other stuff involving network requests end end -- Location event listener Runtime:addEventListener( "location", locationHandler );

Can you post your build.settings?

Rob

Hi Rob,

build.settings:

settings = { orientation = { default = "portrait", supported = { "portrait", "portraitUpsideDown" }, }, android = { versionCode = 20000, coronaWindowMovesWhenKeyboardAppears = true, usesPermissions = { "android.permission.INTERNET", -- Permission to retrieve current location from the GPS "android.permission.ACCESS\_FINE\_LOCATION", -- Permission to retrieve current location from WiFi or cellular service "android.permission.ACCESS\_COARSE\_LOCATION", -- "android.permission.GET\_ACCOUNTS", -- "android.permission.RECEIVE\_BOOT\_COMPLETED", -- "com.google.android.c2dm.permission.RECEIVE", -- ".permission.C2D\_MESSAGE", }, -- permissions = -- { -- { name = ".permission.C2D\_MESSAGE", protectionLevel = "signature" }, -- }, }, plugins = { ["facebook"] = { publisherId = "com.coronalabs" }, ["plugin.OneSignal"] = { publisherId = "com.onesignal", }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true, ["android-kindle"]=true }, }, }, iphone = { plist = { -- CFBundleDisplayName = "My Corona App", -- CFBundleName = "My Corona App", -- MinimumOSVersion = "7.0", UIPrerenderedIcon = false, UIApplicationExitsOnSuspend = false, UIStatusBarHidden = true, UIAppFonts = { "FuturaBT-Medium.ttf","FuturaBT-Bold.ttf" }, CFBundleIconFiles = { "Icon", "Icon-60", "Icon-72", "Icon-76", "Icon-Small-40", "Icon-Small-50", "Icon-Small", }, UILaunchImages = { { -- iPhone 4 Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{320, 480}" }, { -- iPhone 5 Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default-568h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{320, 568}" }, { -- iPad Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default-Portrait", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{768, 1024}" }, { -- iPhone 6 Portrait ["UILaunchImageMinimumOSVersion"] = "8.0", ["UILaunchImageName"] = "Default-667h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{375, 667}" }, { -- iPhone 6 Plus Portrait ["UILaunchImageMinimumOSVersion"] = "8.0", ["UILaunchImageName"] = "Default-736h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{414, 736}" }, }, FacebookAppID = "", --replace XXXXXXXXXX with your Facebook App ID CFBundleURLTypes = { { CFBundleURLSchemes = { "", } } --replace XXXXXXXXXX with your Facebook App ID }, UIBackgroundModes = {"remote-notification"}, }, }, }

Hi! Any news on this?

-Sam

Hi Sam,

As usual in cases like this, I suggest that you test out one of our sample apps to see if the issue is duplicated.

https://github.com/coronalabs/samples-coronasdk/tree/master/Hardware/GPS

This is also located in your local Corona SDK application folder in the “SampleCode > Hardware” folder.

Brent

I think iOS 9 may require you to have this key in your plist table in build.settings:

NSLocationWhenInUseUsageDescription = “This app uses maps and GPS when active to determine where to report weather for.”,

The text you write yourself. I would be willing to bet that your console log from the device is complaining about that key not being there.

Rob

Well Gents,

I couldn’t try it out because now I’m running into a load of other issues, which I’ve put in their own topic:

https://forums.coronalabs.com/topic/60136-bunch-of-errors-sdk-mismatch-unusable-profiles/

Can you post your build.settings?

Rob

Hi Rob,

build.settings:

settings = { orientation = { default = "portrait", supported = { "portrait", "portraitUpsideDown" }, }, android = { versionCode = 20000, coronaWindowMovesWhenKeyboardAppears = true, usesPermissions = { "android.permission.INTERNET", -- Permission to retrieve current location from the GPS "android.permission.ACCESS\_FINE\_LOCATION", -- Permission to retrieve current location from WiFi or cellular service "android.permission.ACCESS\_COARSE\_LOCATION", -- "android.permission.GET\_ACCOUNTS", -- "android.permission.RECEIVE\_BOOT\_COMPLETED", -- "com.google.android.c2dm.permission.RECEIVE", -- ".permission.C2D\_MESSAGE", }, -- permissions = -- { -- { name = ".permission.C2D\_MESSAGE", protectionLevel = "signature" }, -- }, }, plugins = { ["facebook"] = { publisherId = "com.coronalabs" }, ["plugin.OneSignal"] = { publisherId = "com.onesignal", }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true, ["android-kindle"]=true }, }, }, iphone = { plist = { -- CFBundleDisplayName = "My Corona App", -- CFBundleName = "My Corona App", -- MinimumOSVersion = "7.0", UIPrerenderedIcon = false, UIApplicationExitsOnSuspend = false, UIStatusBarHidden = true, UIAppFonts = { "FuturaBT-Medium.ttf","FuturaBT-Bold.ttf" }, CFBundleIconFiles = { "Icon", "Icon-60", "Icon-72", "Icon-76", "Icon-Small-40", "Icon-Small-50", "Icon-Small", }, UILaunchImages = { { -- iPhone 4 Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{320, 480}" }, { -- iPhone 5 Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default-568h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{320, 568}" }, { -- iPad Portrait ["UILaunchImageMinimumOSVersion"] = "7.0", ["UILaunchImageName"] = "Default-Portrait", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{768, 1024}" }, { -- iPhone 6 Portrait ["UILaunchImageMinimumOSVersion"] = "8.0", ["UILaunchImageName"] = "Default-667h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{375, 667}" }, { -- iPhone 6 Plus Portrait ["UILaunchImageMinimumOSVersion"] = "8.0", ["UILaunchImageName"] = "Default-736h", ["UILaunchImageOrientation"] = "Portrait", ["UILaunchImageSize"] = "{414, 736}" }, }, FacebookAppID = "", --replace XXXXXXXXXX with your Facebook App ID CFBundleURLTypes = { { CFBundleURLSchemes = { "", } } --replace XXXXXXXXXX with your Facebook App ID }, UIBackgroundModes = {"remote-notification"}, }, }, }

Hi! Any news on this?

-Sam

Hi Sam,

As usual in cases like this, I suggest that you test out one of our sample apps to see if the issue is duplicated.

https://github.com/coronalabs/samples-coronasdk/tree/master/Hardware/GPS

This is also located in your local Corona SDK application folder in the “SampleCode > Hardware” folder.

Brent

I think iOS 9 may require you to have this key in your plist table in build.settings:

NSLocationWhenInUseUsageDescription = “This app uses maps and GPS when active to determine where to report weather for.”,

The text you write yourself. I would be willing to bet that your console log from the device is complaining about that key not being there.

Rob

Well Gents,

I couldn’t try it out because now I’m running into a load of other issues, which I’ve put in their own topic:

https://forums.coronalabs.com/topic/60136-bunch-of-errors-sdk-mismatch-unusable-profiles/