12

I need to detect weather IPhone is in Airplane mode or Not, i have done much research and i found no direct way to achieve that . My App has the functionality of Calling a Number and When an Iphone has Airplane mode he can't call.

so I need to show him my custom Screen to Notify that Airplane mode is enable.

it will be good if any one can explain how we can achieve it in an effective way.

1

4 Answers 4

9

Here is another way to detect this mode like below,

go Info.plist -> add this **Application uses Wi-Fi (Boolean) YES*

To test: Kill your app -> turn on airplane mode -> open ur app: you should be able to see alert within the app.

enter image description here

2
  • Can I track what the user pressed when a view appears with buttons settings and just Ok ?
    – JiosDev
    Feb 24, 2021 at 15:51
  • 1
    No i don't think so Feb 25, 2021 at 9:57
2

If you are not submitting to the App Store, you can inspect the status bar using private API to see if the Airplane mode icon is present. This is checking the status bar view hierarchy to see if there is a UIStatusBarAirplaneModeItemView in the subviews.

In addition to not being App Store safe, this method also requires your app to show the status bar. This is also fragile and subject to break any time Apple decides to change the status bar structure.

if let statusBarSubviews = ((UIApplication.shared.value(forKey: "statusBar") as? UIView)?.value(forKey: "foregroundView") as? UIView)?.subviews,
    statusBarSubviews.contains(where: { $0.classForCoder == NSClassFromString("UIStatusBarAirplaneModeItemView") }) {
        print("Airplane mode is on.")
}
1

Try using SCNetworkReachabilityGetFlags (SystemConfiguration framework). If the flags variable handed back is 0 and the return value is YES, airplane mode is turned on.

Check out Apple's Reachability classes.

There is no built-in api to determine if Airplane mode is on. You have to check if the respective services are available, depending on what you need in your app.

5
1

Since iOS 4.0, you can use CoreTelephony framework:

import CoreTelephony

func isAirplaneModeEnabled() -> Bool? {
  let networkInfo = CTTelephonyNetworkInfo()
  guard let radioAccessTechnology = networkInfo.serviceCurrentRadioAccessTechnology else {
    return nil
  }
  return radioAccessTechnology.isEmpty
}

Note that radioAccessTechnology is not empty if you just disable mobile network connection, as phone calls and SMS are still receivable. Anyway, this still works with Wi-Fi + Airplane mode enabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.