我正在学习如何制作短信发送者。
我为电子邮件、Facebook 和 Twitter 创建了一个发件人:所有这些都有效。但是,我的短信发件人在单击按钮时会在运行时引发异常。
这是我的完整堆栈:
2015-07-17 22:43:13.410 Give[15706:340810] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图在目标上呈现一个 nil 模态视图控制器。” *** 首先抛出调用堆栈: ( 0 核心基础 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 给 0x0000000100432742 _TFC4Give14ViewController19sendFromTextMessagefS0_FPSs9AnyObject_T_ + 1058 6 给 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 发送事件:] + 682 12 UIKit 0x00000001011c5541-[UIApplication sendEvent:] + 246 13 UIKit 0x00000001011d2cdc _UIApplicationHandleEventFromQueueEvent + 18265 14 UIKit 0x00000001011ad59c _UIApplicationHandleEventQueue + 2066 15 核心基础 0x0000000100845431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 16 核心基础 0x000000010083b2fd __CFRunLoopDoSources0 + 269 17 核心基础 0x000000010083a934 __CFRunLoopRun + 868 18 核心基础 0x000000010083a366 CFRunLoopRunSpecific + 470 19 图形服务 0x0000000104081a3e GSEventRunModal + 161 20 UIKit 0x00000001011b08c0 UIApplicationMain + 1282 21 给 0x0000000100439ab7 主要 + 135 22 libdyld.dylib 0x0000000108105145 开始 + 1 23 ???0x0000000000000001 0x0 + 1 ) libc++abi.dylib:以 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)
}