1
當我試圖發送一個短信,並有控制器設置像這樣,但我得到一個錯誤信息'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <Ally.TextMessageController: 0x7fd5361278e0>.'
我在我的故事板確信,我將它連接到TextMessageController,所以我不太確定是什麼導致了崩潰。應用程序嘗試對目標呈現零模態視圖控制器發送文本
class TextMessageController: UIViewController, MFMessageComposeViewControllerDelegate {
var phone: String?
override func viewDidLoad() {
super.viewDidLoad()
print(phone)
var messageVC = MFMessageComposeViewController()
messageVC.body = "Hey I need help, are you available";
messageVC.recipients = ["555555555"]
messageVC.messageComposeDelegate = self;
presentViewController(messageVC, animated: false, completion: nil)
// Do any additional setup after loading the view.
}
func canSendText() -> Bool {
return MFMessageComposeViewController.canSendText()
}
func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
self.dismissViewControllerAnimated(true, completion: nil)
switch (result.rawValue) {
case MessageComposeResultCancelled.rawValue:
print("Message was cancelled")
self.dismissViewControllerAnimated(true, completion: nil)
case MessageComposeResultFailed.rawValue:
print("Message failed")
self.dismissViewControllerAnimated(true, completion: nil)
case MessageComposeResultSent.rawValue:
print("Message was sent")
self.dismissViewControllerAnimated(true, completion: nil)
default:
break;
}
}
以下是錯誤消息
'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <Ally.TextMessageController: 0x7fd5361278e0>.'