From 8f83463aa9077c41c6e8a544a66d72ceda5ff7a1 Mon Sep 17 00:00:00 2001 From: Kevin McGill Date: Wed, 10 Oct 2018 20:36:49 -0500 Subject: [PATCH 1/2] Make sure iOS callback is called correctly --- .gitignore | 1 + ios/Classes/SwiftFlutterSmsPlugin.swift | 29 +++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 7bf00e8..4c70518 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ pubspec.lock # Directory created by dartdoc # If you don't generate documentation locally you can remove this line. doc/api/ +.idea diff --git a/ios/Classes/SwiftFlutterSmsPlugin.swift b/ios/Classes/SwiftFlutterSmsPlugin.swift index a1596a2..acb1042 100644 --- a/ios/Classes/SwiftFlutterSmsPlugin.swift +++ b/ios/Classes/SwiftFlutterSmsPlugin.swift @@ -3,11 +3,11 @@ import UIKit import MessageUI public class SwiftFlutterSmsPlugin: NSObject, FlutterPlugin, UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate { - var message = "Please Send Message" - var _arguments = [String: Any]() + var result: FlutterResult? + var _arguments = [String: Any]() public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel(name: "flutter_sms", binaryMessenger: registrar.messenger()) + let channel = FlutterMethodChannel(name: "flutter_sms", binaryMessenger: registrar.messenger()) let instance = SwiftFlutterSmsPlugin() registrar.addMethodCallDelegate(instance, channel: channel) } @@ -17,14 +17,14 @@ public class SwiftFlutterSmsPlugin: NSObject, FlutterPlugin, UINavigationControl switch call.method { case "sendSMS": #if targetEnvironment(simulator) - result(FlutterError(code: "message_not_sent", message: "Cannot send message on this device!", details: "Cannot send SMS and MMS on a Simulator. Test on a real device.")) + result(FlutterError(code: "message_not_sent", message: "Cannot send message on this device!", details: "Cannot send SMS and MMS on a Simulator. Test on a real device.")) #else - let controller = MFMessageComposeViewController() - controller.body = _arguments["message"] as? String - controller.recipients = _arguments["recipients"] as? [String] - controller.messageComposeDelegate = self - UIApplication.shared.keyWindow?.rootViewController?.present(controller, animated: true, completion: nil) - result(message) + self.result = result + let controller = MFMessageComposeViewController() + controller.body = _arguments["message"] as? String + controller.recipients = _arguments["recipients"] as? [String] + controller.messageComposeDelegate = self + UIApplication.shared.keyWindow?.rootViewController?.present(controller, animated: true, completion: nil) #endif default: result(FlutterMethodNotImplemented) @@ -33,7 +33,14 @@ public class SwiftFlutterSmsPlugin: NSObject, FlutterPlugin, UINavigationControl } public func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) { + let map: [MessageComposeResult: String] = [ + MessageComposeResult.sent: "sent", + MessageComposeResult.cancelled: "cancelled", + MessageComposeResult.failed: "failed", + ] + if let callback = self.result { + callback(map[result]) + } UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: true, completion: nil) - message = "Sent!" } } From 3580946b2aa77bc9e8c56386d9105f29b113c9cb Mon Sep 17 00:00:00 2001 From: Kevin McGill Date: Wed, 10 Oct 2018 20:39:24 -0500 Subject: [PATCH 2/2] Remove unneeded .idea folder --- .idea/codeStyles/Project.xml | 29 -- .idea/libraries/Dart_SDK.xml | 19 -- .idea/libraries/Flutter_Plugins.xml | 9 - .idea/libraries/Flutter_for_Android.xml | 9 - .idea/misc.xml | 28 -- .idea/modules.xml | 9 - .../example_lib_main_dart.xml | 6 - .idea/runConfigurations/main_dart.xml | 6 - .idea/workspace.xml | 259 ------------------ 9 files changed, 374 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/libraries/Dart_SDK.xml delete mode 100644 .idea/libraries/Flutter_Plugins.xml delete mode 100644 .idea/libraries/Flutter_for_Android.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations/example_lib_main_dart.xml delete mode 100644 .idea/runConfigurations/main_dart.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml deleted file mode 100644 index df0a084..0000000 --- a/.idea/libraries/Dart_SDK.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml deleted file mode 100644 index 53449da..0000000 --- a/.idea/libraries/Flutter_Plugins.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Flutter_for_Android.xml b/.idea/libraries/Flutter_for_Android.xml deleted file mode 100644 index 4e96414..0000000 --- a/.idea/libraries/Flutter_for_Android.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 3268472..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index bfb9971..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/runConfigurations/example_lib_main_dart.xml b/.idea/runConfigurations/example_lib_main_dart.xml deleted file mode 100644 index 5fd9159..0000000 --- a/.idea/runConfigurations/example_lib_main_dart.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/main_dart.xml b/.idea/runConfigurations/main_dart.xml deleted file mode 100644 index aab7b5c..0000000 --- a/.idea/runConfigurations/main_dart.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 25bed21..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,259 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1534353795796 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file