IOS Location Services On/Off

I'm trying to find a solution to a problem I have with the "location" event listener when IOS "Location Services" is Off. When my application sets an event listener, Runtime:addEventListener( "location", locationHandler ), and the IOS "Location Services" is Off the application crashes.

I'm hoping somebody may have a way to check the app's "Location Services" setting, so that I can run a check before calling "Runtime:addEventListener( "location", locationHandler )", and prevent the crash. Anybody have any ideas?

Thanks in advance for your help.

Actually this shouldn't crash and the problem is probably in your code. For example in the example code, the code tries to do a string.format on fields in the event table that won't exist in this case.

So we do have a documentation omission. When location services fails to work on iOS, it will send an error event to your location listener. The error event is a table with two fields, errorCode and errorMessage (first is a number, second is a string). You should check to see if event.errorCode or event.errorMessage exist first. If they do, you want to avoid accessing any other table properties like event.latitude.

Thanks for the response, that helped a lot. I did find my cause for the crash or what looked like a crash. My application was looking for a suspend and then calls os.exit. When the iOS Location Services displays the message to allow location services it suspends the application. The suspension of the application caused it to exit. Once I removed the os.exit on suspension everything worked great.

views:1707 update:2011/12/1 20:56:45
corona forums © 2003-2011