Ios+swift: Send SMS with Messageui.framework

Source: Internet
Author: User

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

  1. Add Messageui.framework Frame
  2. For the Viewcontroller class

    • Add Uinavigationcontrollerdelegate, Mfmessagecomposeviewcontrollerdelegate interface
    • Implement the Func Messagecomposeviewcontroller (controller:mfmessagecomposeviewcontroller!, didfinishwithresult result: Messagecomposeresult)
  3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.