viewServiceDidTerminateWithError:Error Domain = _UIViewServiceInterfaceErrorDomain Code = 3“(null)”UserInfo = {Message = Service Connection Interrupted}

时间:2015-10-07 09:42:06

标签: ios swift swift2 xcode7

邮件服务在swift中显示错误。错误消息是 viewServiceDidTerminateWithError:Error Domain = _UIViewServiceInterfaceErrorDomain Code = 3“(null)”UserInfo = {Message = Service Connection Interrupted} 。我已提供以下代码供参考。

if MFMailComposeViewController.canSendMail() {
        print("can send")
    } else {

        print("cannot send")
    }

    let mail = MFMailComposeViewController()
    mail.mailComposeDelegate = self
    mail.setSubject("DoctorVisit_\(rep_doc_visit_date[indexPath.row])")
    mail.setMessageBody("Hi, Please find attached doctor visit report. Thanks.", isHTML: false)

    let documentsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as NSString

    let pdfFileName = documentsPath.stringByAppendingPathComponent("report.pdf")

    if let fileData = NSData(contentsOfFile: pdfFileName) {

        print("File data loaded.")
        mail.addAttachmentData(fileData, mimeType: "application/pdf", fileName: "report")
    }
    self.presentViewController(mail, animated: true, completion: nil)

}

func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

0 个答案:

没有答案