首页 > 代码库 > iOS+Swift: 使用MessageUI.framework发送短信
iOS+Swift: 使用MessageUI.framework发送短信
在iOS中, 可以使用MessageUI.framework框架发送短信, 步骤如下:
代码下载http://git.oschina.net/yao_yu/swift_cnblogs_samples/tree/master/Y0001_SendSMS
- 添加MessageUI.framework框架
为ViewController类
- 添加UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate 接口
- 实现func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult)
发送短信很简单
func sendSMS(){ if MFMessageComposeViewController.canSendText(){ let controller = MFMessageComposeViewController() controller.body = txtSMS.text controller.recipients = txtTo.text.componentsSeparatedByString(",") controller.messageComposeDelegate = self self.presentViewController(controller, animated: true, completion: nil) } else { let alert = UIAlertView(title: "提示信息", message: "本设备不能发短信", delegate: nil, cancelButtonTitle: "确定") alert.show() }}func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) { controller.dismissViewControllerAnimated(true, completion: nil) switch result.value{ case MessageComposeResultSent.value: lblResult.text = "短信已发送" case MessageComposeResultCancelled.value: lblResult.text = "短信已取消" case MessageComposeResultFailed.value: lblResult.text = "短信发送失败" default: break }}
iOS+Swift: 使用MessageUI.framework发送短信
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。