In iOS, you can use the Messageui.framework framework to send text messages in the following steps:
Code Download Http://git.oschina.net/yao_yu/swift_cnblogs_samples/tree/master/Y0001_SendSMS
- Add Messageui.framework Frame
For the Viewcontroller class
- Add Uinavigationcontrollerdelegate, Mfmessagecomposeviewcontrollerdelegate interface
- Implement the Func Messagecomposeviewcontroller (controller:mfmessagecomposeviewcontroller!, didfinishwithresult result: Messagecomposeresult)
Sending a text message is simple
func sendsms () {if Mfmessagecomposeviewcontroller.cansendtext () {Let Controller = Mfmessagecomposeviewcontr Oller () Controller.body = Txtsms.text controller.recipients = txtTo.text.componentsSeparatedByString (",") Controller.messagecomposedelegate = Self Self.presentviewcontroller (Controller, Animated:true, Completion:ni L)} else {Let alert = Uialertview (title: "Prompt Message", message: "This device cannot send text messages", Delegate:nil, Cancelbuttontitle: "OK") Alert.show ()}}func Messagecomposeviewcontroller (controller:mfmessagecomposeviewcontroller!, DidFinishWithResul T result:messagecomposeresult) {controller.dismissviewcontrolleranimated (true, completion:nil) switch Result.valu e{Case MessageComposeResultSent.value:lblResult.text = "SMS Sent" case Messagecomposeresultcancelled.value: Lblresult.text = "SMS Canceled" Case MessageComposeResultFailed.value:lblResult.text = "SMS Send Failed" default: Break}}
Ios+swift: Use messageui.framework to send text messages