【问题标题】:Trying to email photo attachment without edit screen尝试在没有编辑屏幕的情况下通过电子邮件发送照片附件
【发布时间】:2015-06-25 20:56:10
【问题描述】:

我正在尝试在不显示编辑器的情况下发送带有照片附件的电子邮件。最终我试图做到这一点,所以当有人登录应用程序时,它会自动向他们发送一封电子邮件。

我的实现:

if let videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) {
    videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
    //initiates a still image and returns
    //samplebugger data was captured
    stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {(sampleBuffer, error) in
        if (sampleBuffer != nil) {
            var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
            //creates core graphics image
            var dataProvider = CGDataProviderCreateWithCFData(imageData)
            var cgImageRef = CGImageCreateWithJPEGDataProvider(dataProvider, nil, true, kCGRenderingIntentDefault)

            var image = UIImage(CGImage: cgImageRef, scale: 1.0, orientation: UIImageOrientation.Right)

            //saves image after taken
            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)

            var myController =  MFMailComposeViewController()
            myController.mailComposeDelegate = self
            myController.setSubject(" Your Sherpa Photo")
            myController.setMessageBody("hello World", isHTML: false)
            myController.setToRecipients(["keli5466@colorado.edu"])


            var emailimageData =  UIImagePNGRepresentation(image)
            myController.addAttachmentData(emailimageData, mimeType: "image/png", fileName: "image")
            self.presentViewController(myController, animated: true, completion: nil)
        }
    })
}

// ...

func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
    if result.value == MFMailComposeResultSent.value {
        let alertView = UIAlertView()
        alertView.message = "Mail Sent!"
        alertView.addButtonWithTitle("OK")

        alertView.show()
    }

    self.dismissViewControllerAnimated(false, completion: nil)
}

【问题讨论】:

标签: ios swift mfmailcomposeviewcontroller


【解决方案1】:

简短回答:您不能这样做,这是设计使然。您可以在不显示撰写邮件视图控制器的情况下发送电子邮件的唯一方法是,如果您有一个提供邮件服务的服务器,但您必须收集用户的邮件凭据。

Apple 不希望第 3 方开发人员从用户帐户发送电子邮件,而用户是单击按钮并进行发送的人。这可以保护用户免受应用程序在用户不知情或未经许可的情况下发送邮件。

想象一下,如果没有这个限制,垃圾邮件的爆炸式增长。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多