UPDATE: As of some version of iOS 8 (8.3, maybe), GPS hardware can be turned on even in airplane mode (i.e., you can get GPS location even in airplane mode). This renders this question moot.
--
Is it possible to programatically determine if an iPhone is in Airplane Mode? I specifically want to know if it's in AirPlane Mode, as opposed to having (or not having) a network connection. This question has been asked a lot, but every answer I've seen has referred to Apple's Reachability code to determine if a network connection is available.
I'm writing an app that uses the iPhone's GPS. At the moment, if Airplane Mode is on and my app is launched, my location manager object still appears to exist and still appears to be giving me a (cached?) location. The little GPS icon appears in the status bar to let me know that my app is determining a location.
I want to know if the phone's in Airplane Mode so that I can not initialise the location manager object and I can change my UI to indicate to the user that GPS functionality is not available.
The GPS functionality can obviously be used regardless of network connectivity, so a lack of network connectivity strikes me as being a poor proxy for Airplane Mode. I don't appear to get any specific errors (through locationManager: didFailWithError) when in Airplane Mode, just a generic error that I'm assuming could come from a number of sources.
Similar requirements for my app, except I knew in advance that it would most likely be used in a "no cell signal" environment (camping in a remote area) and that the user might put the device in airplane mode to conserve batteries, without realizing it shuts down GPS.
Since airplane mode does not result in an didFailWithError, and locationServicesEnabled returns yes, I set a timer for 60 seconds, and if no GPS reading is returned before the timer expires, I display a message to the user telling them that GPS data can't be read, and suggest they check that airplane mode is not enabled, and that they ensure they have a clear view of the sky.
One solution might be to take a screenshot of the device and look at the colors present in that region. If they're orange, you're in airplane mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With