标签:
import UIKit import MessageUI class ViewController: UIViewController ,UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate{ override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //首先要判断设备具不具备发送短信功能 if MFMessageComposeViewController.canSendText(){ let controller = MFMessageComposeViewController() //设置短信内容 controller.body = "短信内容:欢迎来到hangge.com" //设置收件人列表 controller.recipients = ["123456","120000"] //设置代理 controller.messageComposeDelegate = self //打开界面 self.presentViewController(controller, animated: true, completion: { () -> Void in }) }else{ println("本设备不能发送短信") } } //发送短信代理 func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) { controller.dismissViewControllerAnimated(true, completion: nil) switch result.value{ case MessageComposeResultSent.value: println("短信已发送") case MessageComposeResultCancelled.value: println("短信取消发送") case MessageComposeResultFailed.value: println("短信发送失败") default: break } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4843605.html