前端之家收集整理的这篇文章主要介绍了
Swift短信分享,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
功能:用于短信分享内容
func sendMessage() {
if (self.canSendText()) {
self.presentViewController(self.configuredMessageComposeViewController(),animated: true,completion: nil)
} else {
MPAlertView.showAlertView("当前设备不支持短信功能")
}
}
func canSendText() -> Bool {
return MFMessageComposeViewController.canSendText()
}
func configuredMessageComposeViewController() -> MFMessageComposeViewController {
let messageComposeVC = MFMessageComposeViewController()
messageComposeVC.messageComposeDelegate = self
let inviteCode = NSUserDefaults.standardUserDefaults().stringForKey(kInviteCode)
messageComposeVC.body = "短信内容"
return messageComposeVC
}
func messageComposeViewController(controller: MFMessageComposeViewController!,didFinishWithResult result: MessageComposeResult) {
switch result.value {
case 0:
MPAlertView.showAlertView("取消发送")
self.dismissViewControllerAnimated(true,completion: nil)
case 1:
MPAlertView.showAlertView("发送失败")
self.dismissViewControllerAnimated(true,completion: nil)
case 2:
MPAlertView.showAlertView("发送成功")
self.dismissViewControllerAnimated(true,completion: nil)
default:
controller.dismissViewControllerAnimated(true,completion: nil)
}
self.dismissViewControllerAnimated(true,completion: nil)
}