2015-06-25 18 views
0

我試圖發送附有照片附件的電子郵件而不顯示編輯器。最終,我試圖在有人登錄到應用程序時自動發送電子郵件給他們。試圖在沒有編輯屏幕的情況下通過電子郵件發送附件照片

我的實現:

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(["[email protected]"]) 


      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) 
} 
+0

可能重複[發送郵件沒有MFMailComposeViewController](http://stackoverflow.com/questions/1263412/send-mail-without-mfmailcomposeviewcontroller) – JAL

回答

1

簡短的回答:你不能做到這一點,通過設計。在不顯示組合郵件視圖控制器的情況下發送電子郵件的唯一方法是如果您有提供郵件服務的服務器,但您必須收集用戶的郵件憑證。

Apple不希望第三方開發者從用戶的帳戶發送電子郵件,用戶是單擊該按鈕並進行發送的用戶。這可以保護用戶免受應用程序發送郵件而無需用戶的知識或權限。

想象一下如果這個限制不到位,垃圾郵件的爆炸式增長。

相關問題