我正在构建一个简单的应用程序,可以从UIImagePickerController
(从相机或照片库,取决于用户选择)获取图像并将其发送到服务器。
后者似乎是将图像保存在App内部文件夹中,因为当我拍摄任何照片时,在Xcode的“磁盘调试”菜单中,每次在磁盘上写入1-5 MB时,我都可以看到。照片库中的图像也会发生同样的情况,它们也占用大约1 MB。
这是代码,非常基本: (VisualRecognition是使用其AI服务之一的IBM API)
let imagePicker = UIImagePickerController()
var imageShot = UIImage() //To send later the image to the server
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let userPickedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
imageShot = userPickedImage
picker.dismiss(animated: true) {
self.elaborateImage(self.imageShot). //The sending function
}
}
func elaborateImage(_ image: UIImage) {
animateIn()
let group = DispatchGroup()
group.enter()
DispatchQueue.main.async {
let visualRecognition = VisualRecognition(version: self.version, apiKey: self.apiKey)
visualRecognition.classify(image: image, acceptLanguage: self.language, failure: { (error) in
print("There was an error")
}, success: { (classifiedImage) in
let classes = classifiedImage.images.first!.classifiers.first!.classes
var classificationResults = [ScanResult]()
for index in 0..<classes.count {
let scan = ScanResult.init(score: Int(classes[index].score! * 100), name: classes[index].className)
classificationResults.append(scan)
}
self.sortedClassificationResults = classificationResults.sorted(by: {$0.score > $1.score})
group.leave()
})
}
group.notify(queue: .main) {
self.performSegue(withIdentifier: "goToResults", sender: self)
}
}
将图像发送到服务器后我不再需要它们,但是它们会继续增加应用程序的大小。
如何停止UIImagePickerController
将图像保存在App Bundle中?
谢谢