How to determine flight mode / flight mode in iOS Swift

I need to determine the weather that the iPhone is in airplane mode or not, I did a lot of research, and I did not find a direct way to achieve this. My application has Call Number functionality, and when Iphone has a flight mode, it cannot make a call.

so I need to show him my own screen to let me know that airplane mode is on.

it will be good if someone can explain how we can do this effectively.

+8
source share
3 answers

Here is another way to detect this mode, as shown below,

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

To check: kill your application → turn on airplane mode → open ur application: you should see a warning in the application.

enter image description here

+6
source

Try using SCNetworkReachabilityGetFlags (Framework SystemConfiguration). If the return flag variable is 0 and the return value is YES, airplane mode is turned on.

Check out Apple Valid Classes .

There is no built-in api to determine if airplane mode is on. You should check if the appropriate services are available, depending on what you need in your application.

+1
source

If you are not sending a request to the App Store, you can check the status bar using the private API to see if the flight mode icon is present. This checks the hierarchy of the status bar view to see if there is a UIStatusBarAirplaneModeItemView in the UIStatusBarAirplaneModeItemView .

In addition to being unsafe on the App Store, this method also requires your application to display a status bar. It is also fragile and can be broken every time Apple decides to change the structure of the status bar.

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

All Articles