我想从我的UITableViewController发送短信,但发送或取消后短信窗口不会被忽略。
import MessageUI
class TableViewController: UITableViewController, UISearchResultsUpdating {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let msgVC = MFMessageComposeViewController()
msgVC.recipients = ["555555"]
self.presentViewController(msgVC, animated: true, completion: nil)
}
func messageComposeViewController(controller: MFMessageComposeViewController!,
didFinishWithResult result: MessageComposeResult) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
答案 0 :(得分:4)
您从未设置messageComposeDelegate
。
import MessageUI
class TableViewController: UITableViewController, UISearchResultsUpdating, MFMessageComposeViewControllerDelegate {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let msgVC = MFMessageComposeViewController()
msgVC.messageComposeDelegate = self
msgVC.recipients = ["555555"]
self.presentViewController(msgVC, animated: true, completion: nil)
}
func messageComposeViewController(controller: MFMessageComposeViewController!,
didFinishWithResult result: MessageComposeResult) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
您还应确认设备已设置为发送消息。请阅读MFMessageComposeViewController
课程的文档。它解释了所有这些并显示了示例代码。
答案 1 :(得分:0)