From ced0c568fbfc2cc57c63128f06a14bba8847363a Mon Sep 17 00:00:00 2001 From: Ayush Bherwani Date: Tue, 13 Oct 2020 03:24:15 +0530 Subject: [PATCH] [platform_channels] adds ios implementation for MethodChannel demo (#563) --- platform_channels/ios/Flutter/.last_build_id | 1 + .../ios/Runner.xcodeproj/project.pbxproj | 3 -- .../ios/Runner/AppDelegate.swift | 33 +++++++++++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 platform_channels/ios/Flutter/.last_build_id diff --git a/platform_channels/ios/Flutter/.last_build_id b/platform_channels/ios/Flutter/.last_build_id new file mode 100644 index 000000000..a23b6bae7 --- /dev/null +++ b/platform_channels/ios/Flutter/.last_build_id @@ -0,0 +1 @@ +dad366ac47fa5a1d30c8533697937d44 \ No newline at end of file diff --git a/platform_channels/ios/Runner.xcodeproj/project.pbxproj b/platform_channels/ios/Runner.xcodeproj/project.pbxproj index 73cb7672e..dccd2beb9 100644 --- a/platform_channels/ios/Runner.xcodeproj/project.pbxproj +++ b/platform_channels/ios/Runner.xcodeproj/project.pbxproj @@ -241,7 +241,6 @@ /* Begin XCBuildConfiguration section */ 249021D3217E4FDB00AE95B9 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -318,7 +317,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -374,7 +372,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; diff --git a/platform_channels/ios/Runner/AppDelegate.swift b/platform_channels/ios/Runner/AppDelegate.swift index 70693e4a8..0ae04b187 100644 --- a/platform_channels/ios/Runner/AppDelegate.swift +++ b/platform_channels/ios/Runner/AppDelegate.swift @@ -3,11 +3,30 @@ import Flutter @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { - override func application( - _ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? - ) -> Bool { - GeneratedPluginRegistrant.register(with: self) - return super.application(application, didFinishLaunchingWithOptions: launchOptions) - } + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + let flutterViewController = window.rootViewController as! FlutterViewController + FlutterMethodChannel(name: "methodChannelDemo", binaryMessenger: flutterViewController.binaryMessenger).setMethodCallHandler({ + (call: FlutterMethodCall, result: FlutterResult) -> Void in + + guard let count = (call.arguments as? NSDictionary)?["count"] as? Int else { + result(FlutterError(code: "INVALID_ARGUMENT", message: "Value of count cannot be null", details: nil)) + return + } + + switch call.method { + case "increment": + result(count + 1) + case "decrement": + result(count - 1) + default: + result(FlutterMethodNotImplemented) + } + }) + + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } }