gpt4 book ai didi

ios - 拍照不保存到手机

转载 作者:行者123 更新时间:2023-11-28 07:42:02 24 4
gpt4 key购买 nike

我正在开发一个 ios 应用程序,用户可以在其中使用手机摄像头拍摄图像并通过电子邮件发送,而无需将其保存在手机中(出于保密原因)。
我在谷歌中搜索但找不到任何有用的东西。
这可能吗 ?如果没有,是否有任何变通办法?

最佳答案

试试这个,我只是为你制作的,试试临时文件的部分,我在最后告诉我是谁做的。问候

import UIKit
import MobileCoreServices
import MessageUI

class PictureViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, MFMailComposeViewControllerDelegate {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}


@IBAction func editImage()
{
let alerta = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
var accionCamera = UIAlertAction()
if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera))
{
accionCamera = UIAlertAction(title: "Take a picture", style: .default, handler: { (ACTION) in
self.pickMediaFromSource(UIImagePickerControllerSourceType.camera)
})
alerta.addAction(accionCamera)
}

let accionNo = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alerta.addAction(accionNo)
present(alerta, animated: true, completion: nil)
}

func pickMediaFromSource(_ sourceType:UIImagePickerControllerSourceType)
{
let mediaTypes = UIImagePickerController.availableMediaTypes(for: sourceType)!
if UIImagePickerController.isSourceTypeAvailable(sourceType) && mediaTypes.count > 0
{
let picker = UIImagePickerController()
picker.mediaTypes = mediaTypes
picker.delegate = self
picker.sourceType = sourceType

present(picker, animated: true, completion: nil)
}
else
{
let alertController = UIAlertController(title:"Error", message: "Media not supported", preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.destructive, handler: nil)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
let lastChosenMediaType = info[UIImagePickerControllerMediaType] as? String
if let mediaType = lastChosenMediaType
{
if mediaType == kUTTypeImage as String
{
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
picker.dismiss(animated: true) {
self.sendEmailFront(image: image!)
}

let tmpDirectory = try? FileManager.default.contentsOfDirectory(atPath: NSTemporaryDirectory())

}
else if mediaType == kUTTypeMovie as String
{
picker.dismiss(animated: true, completion: {
let alertController = UIAlertController(title:"Error", message: "Medio no soportado. Debe ser una imagen", preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.destructive, handler: nil)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)

})
return

}
}
}


func imagePickerControllerDidCancel(_ picker: UIImagePickerController)
{
picker.dismiss(animated: true, completion:nil)
}

// MARK: - SEND EMAIL
func sendEmailFront(image: UIImage)
{
if MFMailComposeViewController.canSendMail()
{
let dataImage = UIImagePNGRepresentation(image)
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["example@gmail.com"])
mail.addAttachmentData(dataImage!, mimeType: "THE MIME TYPE", fileName: "THE FILE NAME")

self.present(mail, animated: true, completion: nil)
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true) {

// TO CHECK IF EXIST ANY FILE TO DELETE, I DON'T FIND ANYTHING BUT, TRY YOU ANYWAY
let tmpDirectory = try? FileManager.default.contentsOfDirectory(atPath: NSTemporaryDirectory())

let urls = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first
let contents = try? FileManager.default.contentsOfDirectory(at: urls!, includingPropertiesForKeys: nil, options: .skipsPackageDescendants)
print(contents)

}
}


}

关于ios - 拍照不保存到手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52017997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com