文本消息 - 应用程序试图呈现一个零模态视图控制器

时间:2015-07-18 05:46:27

标签: ios messageui

我正在学习如何制作短信发件人。

我为电子邮件,Facebook和Twitter创建了一个发件人:所有这些都有效。但是,单击按钮时,我的文本消息发送方会在运行时抛出异常。

这是我的完整堆栈:

2015-07-17 22:43:13.410 Give[15706:340810] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target .'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000100911c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010247cbb7 objc_exception_throw + 45
    2   UIKit                               0x00000001012ed80d -[UIViewController _presentViewController:withAnimationController:completion:] + 3238
    3   UIKit                               0x00000001012ef6c1 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 132
    4   UIKit                               0x00000001012ef5e5 -[UIViewController presentViewController:animated:completion:] + 229
    5   Give                                0x0000000100432742 _TFC4Give14ViewController19sendFromTextMessagefS0_FPSs9AnyObject_T_ + 1058
    6   Give                                0x00000001004327d6 _TToFC4Give14ViewController19sendFromTextMessagefS0_FPSs9AnyObject_T_ + 54
    7   UIKit                               0x00000001011b1d62 -[UIApplication sendAction:to:from:forEvent:] + 75
    8   UIKit                               0x00000001012c350a -[UIControl _sendActionsForEvents:withEvent:] + 467
    9   UIKit                               0x00000001012c28d9 -[UIControl touchesEnded:withEvent:] + 522
    10  UIKit                               0x00000001011fe958 -[UIWindow _sendTouchesForEvent:] + 735
    11  UIKit                               0x00000001011ff282 -[UIWindow sendEvent:] + 682
    12  UIKit                               0x00000001011c5541 -[UIApplication sendEvent:] + 246
    13  UIKit                               0x00000001011d2cdc _UIApplicationHandleEventFromQueueEvent + 18265
    14  UIKit                               0x00000001011ad59c _UIApplicationHandleEventQueue + 2066
    15  CoreFoundation                      0x0000000100845431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    16  CoreFoundation                      0x000000010083b2fd __CFRunLoopDoSources0 + 269
    17  CoreFoundation                      0x000000010083a934 __CFRunLoopRun + 868
    18  CoreFoundation                      0x000000010083a366 CFRunLoopRunSpecific + 470
    19  GraphicsServices                    0x0000000104081a3e GSEventRunModal + 161
    20  UIKit                               0x00000001011b08c0 UIApplicationMain + 1282
    21  Give                                0x0000000100439ab7 main + 135
    22  libdyld.dylib                       0x0000000108105145 start + 1
    23  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

以下是我发送短信的代码:

@IBAction func sendFromTextMessage(sender: AnyObject) {
    var textMessage = MFMessageComposeViewController() //doesn;t work right now
    textMessage.body = "Check out my amazing campaign app on Give!"
    textMessage.recipients = ["6505555555"] //changed from my real number
    textMessage.messageComposeDelegate = self
    self.presentViewController(textMessage, animated: true, completion: nil)
}

func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
    switch result.value {
    case MessageComposeResultCancelled.value:
        print("Message Cancelled")
    case MessageComposeResultFailed.value:
        print("Message Failed")
    case MessageComposeResultSent.value:
        print("Message Sent")
    default:
        break
    }
    self.dismissViewControllerAnimated(true, completion: nil)
}

0 个答案:

没有答案