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.
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.
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.
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.
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.")
}
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