Skip to content

Instantly share code, notes, and snippets.

@Wenomok
Created April 5, 2023 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wenomok/ea1cf6775ade93e8df2d150eb3bf2557 to your computer and use it in GitHub Desktop.
Save Wenomok/ea1cf6775ade93e8df2d150eb3bf2557 to your computer and use it in GitHub Desktop.
@objc class AppDelegate: FlutterAppDelegate {
let hubMethodChannel: HubMethodChannel = .init()
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
hubMethodChannel.handle()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
class HubMethodChannel: NSObject {
func handle() {
if let controller = UIApplication.shared.delegate?.window??.rootViewController as? FlutterViewController {
let connectToHubChannel = FlutterMethodChannel(name: "dexbee.club/HubConfig",
binaryMessenger: controller.binaryMessenger)
connectToHubChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
switch call.method {
case "scanWiFiHubList":
HubManager.shared.scanWiFiList { wifiModelList in
result(wifiModelList.map({ $0.toDictResult() }))
} onError: { error in
result(error.toFlutterError())
}
default:
result(FlutterMethodNotImplemented)
}
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment