Swift-The implementation of SMS sending function

Source: Internet
Author: User

You can use the Messageui.framework framework to implement the SMS sending function, as follows:(1) First to determine whether the device has the ability to send SMS (2) If the device allows text messages to be sent, create a Mfmessagecomposeviewcontroller view controller, and set the SMS content and recipient number list. (3) After the text message is sent, the callback agent method is executed, which can get the sending result (success, failure or cancellation)
The code is as follows:
Import Uikitimport Messageuiclass Viewcontroller:uiviewcontroller, Uinavigationcontrollerdelegate, mfmessagecomposeviewcontrollerdelegate{override func Viewdidload () {super.viewdidload ()//Do any Addit                ional Setup after loading the view, typically from a nib. First of all to determine the device is not capable of sending SMS function if Mfmessagecomposeviewcontroller.cansendtext () {Let Controller = Mfmessagecomposevi Ewcontroller ()//Set SMS Content controller.body = "SMS content: Welcome to Hangge.com"//Set up recipient list cont Roller.recipients = ["123456", "120000"]//Set proxy controller.messagecomposedelegate = self/                        /Open Interface Self.presentviewcontroller (Controller, Animated:true, completion: {()-Void in })}else{println ("This device cannot send SMS")}}//Send SMS Agent func messagecomposeviewcontroller (CO ntroller:mfmessagecomposeviewcontroller!, Didfinishwithresult Result:messagecomposeresuLT) {controller.dismissviewcontrolleranimated (true, completion:nil) switch result.value{case M                ESSAGECOMPOSERESULTSENT.VALUE:PRINTLN ("SMS Sent") Case Messagecomposeresultcancelled.value: println ("SMS Cancel Send") Case MessageComposeResultFailed.value:println ("SMS Send Failed") d Efault:break}} override func Didreceivememorywarning () {Super.didreceivememorywarni ng ()}}

Swift-The implementation of the SMS Send feature

Related Article

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.