Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Detect Airplane Mode/ Flight Mode in IOS Swift

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.

like image 688
Muhammad Faizan Khatri Avatar asked May 04 '16 10:05

Muhammad Faizan Khatri


People also ask

How do I know if I'm in Airplane Mode?

When you activate airplane mode, it stops all signal transmission from your device. You'll see an airplane icon in your phone's status bar when it's turned on. The feature is known as airplane mode because many airlines prohibit wireless devices on their planes, especially when taking off and landing.

How do I know if iPhone is in Airplane Mode?

Turn on Airplane Mode You can also go to Settings and select Airplane Mode to turn it on. . You can also go to Settings and tap Airplane Mode. You can set your iPhone and Apple Watch to mirror the Airplane Mode setting of the other device.


2 Answers

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

like image 150
Jigar Tarsariya Avatar answered Sep 18 '22 06:09

Jigar Tarsariya


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.")
}
like image 44
Sean Kladek Avatar answered Sep 22 '22 06:09

Sean Kladek