diff --git a/android/src/main/java/flutter/moum/airplane_mode_detection/AirplaneModeDetectionPlugin.java b/android/src/main/java/flutter/moum/airplane_mode_detection/AirplaneModeDetectionPlugin.java index 5992888..fd3d0a5 100644 --- a/android/src/main/java/flutter/moum/airplane_mode_detection/AirplaneModeDetectionPlugin.java +++ b/android/src/main/java/flutter/moum/airplane_mode_detection/AirplaneModeDetectionPlugin.java @@ -32,6 +32,11 @@ public void onMethodCall(MethodCall call, Result result) { result.success("ON"); else result.success("OFF"); + }else if (call.method.equals("isOnAirplaneMode")) { + if(isAirModeOn()) + result.success(true); + else + result.success(false); } else { result.notImplemented(); } diff --git a/ios/Classes/SwiftAirplaneModeDetectionPlugin.swift b/ios/Classes/SwiftAirplaneModeDetectionPlugin.swift index 06ce49c..2143c2b 100644 --- a/ios/Classes/SwiftAirplaneModeDetectionPlugin.swift +++ b/ios/Classes/SwiftAirplaneModeDetectionPlugin.swift @@ -4,55 +4,73 @@ import Network @available(iOS 12.0, *) public class SwiftAirplaneModeDetectionPlugin: NSObject, FlutterPlugin { - public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel(name: "airplane_mode_detection", binaryMessenger: registrar.messenger()) - let instance = SwiftAirplaneModeDetectionPlugin() - registrar.addMethodCallDelegate(instance, channel: channel) - } + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "airplane_mode_detection", binaryMessenger: registrar.messenger()) + let instance = SwiftAirplaneModeDetectionPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } - public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - if (call.method == "getPlatformVersion"){ - result("iOS" + UIDevice.current.systemVersion) - } + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + if (call.method == "getPlatformVersion"){ + result("iOS" + UIDevice.current.systemVersion) + }else if (call.method == "detectAirplaneMode") { + (self.detectAirplaneMode( completion: { (msg) in + result(msg) + })) + }else if (call.method == "isOnAirplaneMode") { + (self.isOnAirplanceMode( completion: { (msg) in + result(msg) + })) + } + } - else if (call.method == "detectAirplaneMode") { - (self.detectAirplaneMode( completion: { (msg) in - result(msg) - })) - } + public override init() { + super.init() + } - } + private func detectAirplaneMode(completion: @escaping (String) -> Void){ + let monitor = NWPathMonitor() + var msg: String = "" + monitor.pathUpdateHandler = { path in + if path.availableInterfaces.count == 0{ + msg = "Flight Mode" + print("Flight Mode") + monitor.cancel() - public override init() { - super.init() - } + } + else { + msg = "Not Flight Mode" + print("Not Flight Mode") + monitor.cancel() + } + completion(msg) + } + let queue = DispatchQueue(label: "Monitor", qos: .default, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil) + monitor.start(queue: queue) + } + + private func isOnAirplanceMode(completion: @escaping (Bool) -> Void){ + let monitor = NWPathMonitor() + var msg: Bool = false + monitor.pathUpdateHandler = { path in + if path.availableInterfaces.count == 0{ + msg = true + print("Flight Mode") + monitor.cancel() - func detectAirplaneMode(completion: @escaping (String) -> Void){ - let monitor = NWPathMonitor() - var msg: String = "" + } + else { + msg = false + print("Not Flight Mode") + monitor.cancel() - - monitor.pathUpdateHandler = { path in - if path.availableInterfaces.count == 0{ - msg = "Flight Mode" - print("Flight Mode") - monitor.cancel() - - } - else { - msg = "Not Flight Mode" - print("Not Flight Mode") - monitor.cancel() - - } - completion(msg) - } - - let queue = DispatchQueue(label: "Monitor", qos: .default, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil) - monitor.start(queue: queue) - - } - } + } + completion(msg) + } + let queue = DispatchQueue(label: "Monitor", qos: .default, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil) + monitor.start(queue: queue) + } +} diff --git a/lib/airplane_mode_detection.dart b/lib/airplane_mode_detection.dart index 6e63484..e66d355 100644 --- a/lib/airplane_mode_detection.dart +++ b/lib/airplane_mode_detection.dart @@ -15,4 +15,9 @@ class AirplaneModeDetection { final String airplanemode = await _channel.invokeMethod('detectAirplaneMode'); return airplanemode; } + + static Future isOnAirplaneMode() async { + final bool isOnAirplaneMode = await _channel.invokeMethod('isOnAirplaneMode'); + return isOnAirplaneMode; + } }