Merge pull request #7 from kmcgill88/iOS-should-check-if-device-canSendText

Add canSendText
This commit is contained in:
Rody Davis 2018-11-16 11:41:34 -05:00 committed by GitHub
commit fb92b1b950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,14 +17,28 @@ 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
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)
if (MFMessageComposeViewController.canSendText()) {
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)
} else {
result(FlutterError(
code: "device_not_capable",
message: "The current device is not capable of sending text messages.",
details: "A device may be unable to send messages if it does not support messaging or if it is not currently configured to send messages. This only applies to the ability to send text messages via iMessage, SMS, and MMS."
)
)
}
#endif
default:
result(FlutterMethodNotImplemented)