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