Skip to content

Instantly share code, notes, and snippets.

@Sumit-Ghosh
Created February 5, 2022 17:14
Show Gist options
  • Save Sumit-Ghosh/25e7e5ceddd6eb0af65a2ca870d35042 to your computer and use it in GitHub Desktop.
Save Sumit-Ghosh/25e7e5ceddd6eb0af65a2ca870d35042 to your computer and use it in GitHub Desktop.
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// 1
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
// 2
let deviceChannel = FlutterMethodChannel(name: "test.flutter.methodchannel/iOS",
binaryMessenger: controller.binaryMessenger)
// 3
prepareMethodHandler(deviceChannel: deviceChannel)
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
private func prepareMethodHandler(deviceChannel: FlutterMethodChannel) {
// 4
deviceChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
// 5
if call.method == "getDeviceModel" {
// 6
self.receiveDeviceModel(result: result)
}
else {
// 9
result(FlutterMethodNotImplemented)
return
}
})
}
private func receiveDeviceModel(result: FlutterResult) {
// 7
let deviceModel = UIDevice.current.model
// 8
result(deviceModel)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment