Ios Swift 3.0:发送短信错误

Ios Swift 3.0:发送短信错误,ios,swift3,sms,runtime-error,appdelegate,Ios,Swift3,Sms,Runtime Error,Appdelegate,我正在尝试发送短信并使用该代码: import UIKit import MessageUI class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } @IBAction func sendMessage(_ s

我正在尝试发送短信并使用该代码:

import UIKit
import MessageUI

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

@IBAction func sendMessage(_ sender: UIButton) {

let messageVC = MFMessageComposeViewController()
messageVC.body = "For a good time call!"
messageVC.recipients = ["79161887060"]
messageVC.messageComposeDelegate = self

self.present(messageVC, animated: true, completion: nil)
}  
}

extension ViewController: MFMessageComposeViewControllerDelegate {
func messageComposeViewController(_ controller:      MFMessageComposeViewController, didFinishWith result: MessageComposeResult)  {
switch (result.rawValue) {
case MessageComposeResult.cancelled.rawValue:
  print("Message was cancelled")
  self.dismiss(animated: true, completion: nil)
case MessageComposeResult.failed.rawValue:
  print("Message failed")
  self.dismiss(animated: true, completion: nil)
case MessageComposeResult.sent.rawValue:
  print("Message was sent")
  self.dismiss(animated: true, completion: nil)
default:
  break;
}
}
}
生成成功,但当我点击按钮(发送sms的操作)时,调试器将转到AppDelegate文件并停止:

日志如下:

2017-02-16 14:06:13.171616注册[24422:1035557]bundleid:XLab.注册,启用\u级别:0,保留\u级别:0,使用\u活动传播\u:0 2017-02-16 14:06:13.172031注册[24422:1035557]子系统:com.apple.siri,类别:Intents,启用\级别:1,持久\级别:1,默认\ ttl:0,信息\ ttl:0,调试\ ttl:0,生成\症状:0,启用\超大:0,隐私\设置:0,启用\私有\数据:0 2017-02-16 14:06:13.177495注册[24422:1035645]子系统:com.apple.UIKit,类别:HIDEventFiltered,启用\u级别:0,持久\u级别:0,默认\u ttl:0,信息\u ttl:0,调试\u ttl:0,生成\u症状:0,启用\u超大:1,隐私\u设置:2,启用\u私有\u数据:0 2017-02-16 14:06:13.180083注册[24422:1035645]子系统:com.apple.UIKit,类别:HIDEventIncoming,启用\u级别:0,持久\u级别:0,默认\u ttl:0,信息\u ttl:0,调试\u ttl:0,生成\u症状:0,启用\u超大:1,隐私\u设置:2,启用\u私有\u数据:0 2017-02-16 14:06:13.190296注册[24422:1035635]子系统:com.apple.BaseBoard,类别:MachPort,启用\u级别:1,持久\u级别:0,默认\u ttl:0,信息\u ttl:0,调试\u ttl:0,生成\u症状:0,启用\u超大:0,隐私\u设置:0,启用\u私有\u数据:0 2017-02-16 14:06:13.204079注册[24422:1035557]子系统:com.apple.UIKit,类别:状态栏,启用\级别:0,持久\级别:0,默认\ ttl:0,信息\ ttl:0,调试\ ttl:0,生成\症状:0,启用\超大:1,隐私\设置:2,启用\私有\数据:0 2017-02-16 14:06:13.296657注册[24422:1035557]子系统:com.apple.UIKit,类别:GestureEnvironment,启用\级别:0,持久\级别:0,默认\ ttl:1,信息\ ttl:0,调试\ ttl:0,生成\症状:0,启用\超大:1,隐私\设置:2,启用\私有\数据:0 2017-02-16 14:06:13.316493注册[24422:1035557]子系统:com.apple.BackBoardServices.fence,类别:App,enable_level:1,persist_level:0,default_ttl:0,info_ttl:0,debug_ttl:0,generate_症状:0,enable_supersize:0,privacy_设置:0,enable_private_数据:0 2017-02-16 14:06:14.350494注册[24422:1035557]子系统:com.apple.UIKit,类别:Touch,enable_level:0,persist_level:0,default_ttl:1,info_ttl:0,debug_ttl:0,generate_symptoms:0,enable_supersize:1,privacy_setting:2,enable_private_data:0 2017-02-16 14:06:14.351481注册[24422:1035557]子系统:com.apple.UIKit,类别:手势,启用\u级别:0,持续\u级别:0,默认\u ttl:1,信息\u ttl:0,调试\u ttl:0,生成\u症状:0,启用\u超大:1,隐私\u设置:2,启用\u私有\u数据:0 2017-02-16 14:06:14.352214注册[24422:1035557]子系统:com.apple.UIKit,类别:手势排除,启用\u级别:0,持久\u级别:0,默认\u ttl:1,信息\u ttl:0,调试\u ttl:0,生成\u症状:0,启用\u超大:1,隐私\u设置:2,启用\u私有\u数据:0 2017-02-16 14:06:14.943772注册[24422:1035557]子系统:com.apple.BackBoardServices.fence,类别:Observer,enable_level:1,persist_level:0,default_ttl:0,info_ttl:0,debug_ttl:0,generate_症状:0,enable_supersize:0,privacy_设置:0,enable_private_数据:0 2017-02-16 14:06:14.944254注册[24422:1035557]子系统:com.apple.BackBoardServices.fence,类别:工作区,启用\级别:1,持久\级别:0,默认\ ttl:0,信息\ ttl:0,调试\ ttl:0,生成\症状:0,启用\超大规模:0,隐私\设置:0,启用\私有\数据:0 2017-02-16 14:06:14.944580注册[24422:1035557]子系统:com.apple.BackBoardServices.fence,类别:跟踪,启用\级别:1,持久\级别:0,默认\ ttl:0,信息\ ttl:0,调试\ ttl:0,生成\症状:0,启用\超大规模:0,隐私\设置:0,启用\私有\数据:0 2017-02-16 14:06:32.331注册[24422:1035557]*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因是:“应用程序试图在目标上呈现无模式视图控制器。” *第一次抛出调用堆栈: ( 0 CoreFoundation 0x00000001107ad34b异常预处理+171 1 libobjc.A.dylib 0x000000010fdf121e objc_异常_抛出+48 2 UIKit 0x000000011A4B867-[UIViewController\u presentViewController:带动画控制器:完成:][5328 3 UIKit 0x000000011A4E3DA \uuu 62-[UIViewController当前视图控制器:动画:完成:]\u块\u调用\u2+70 4 UIKit 0x000000011194fada+[UIView(动画)性能无动画:+90 5 UIKit 0x000000011A4E370 \uuuu 62-[UIViewController呈现视图控制器:动画:完成:]\u块\u调用+365 6 UIKit 0x000000011A4E6DF-[UIViewController\u性能协调演示文稿:动画:][530 7 UIKit 0x000000011A4E1C5-[UIViewController当前视图控制器:动画:完成:][179 8注册0x000000010f7f13da\u TFC12注册14视图控制器17发送SMSBTNClickedFPS9任何对象\u T\u+1002 9注册0x000000010f7f1516\u TTOFC12注册14视图控制器17发送SMSBTNClickedFPS9任何对象 10 UIKit 0x0000000111898b88-[UIApplication sendAction:to:from:forEvent:][83 11 UIKit 0x0000000111AE2B2-[UIControl发送操作:发送到:forEvent:+67 12 UIKit 0x000000011A1E5CB-[UIControl\u发送操作预防:带事件:][444 13 UIKit 0x0000000111a1d4c7-[UIControl触摸附加:带事件:][668
@IBAction func sendMessage(_ sender: UIButton) {
    
        if (MFMessageComposeViewController.canSendText()) {
            let messageVC = MFMessageComposeViewController()
            messageVC.body = "For a good time call!"
            messageVC.recipients = ["79161887060"]
            messageVC.messageComposeDelegate = self
            self.presentViewController(messageVC, animated: true, completion: nil)
        }
   }