5

I have built an app to take safety questionnaires. The app allows to add a photo to individual questions. I use UIImagePickerController for this. Since iOS 11 I noticed that, both in the simulator as well as iPad, selecting an image from the photo library will automatically save the selected image in the tmp folder of the app with a 'temp' name (e.g. 57576A97-21D4-465F-91B6-11215F8B5F97.jpeg). This happens even before didFinishPickingMediaWithIn is performed.

This is my code for setting the UIImagePickerController:

let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .photoLibrary;
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true, completion: nil)

This image is not deleted during the usage of the app. In case the user adds lots of photo's, this would mean that all these photo's will be stored in the tmp directory, which in the end might lead to a crash.

For the moment I have made a work around which searches for the 'temp' files and deletes them each time.

I have checked with the iOS 10.1 simulator, but no copies of the selected image are made in the temp directory (with the same code). When testing on the iPad, using the camera does not lead to 'temp' copies of selected images

My question is: is saving a temp file by the UIImagePicker standard behavior in iOS 11, or can it be avoided?

MarcI
  • 51
  • 5

1 Answers1

1

I've had the same issue before... I don't think there's a way to avoid where the image is saved. I had this issue before and we also managed the deletion of the images ourselfs and this was before iOS 11.

You could use PHAsset from the image picker which results in accessing the image from the photo library so the image is not saved in a temp location?

UPDATE

In my personal project I've had this issue too and I found a simple solution. I move the image from the temp directory in the my app's documents directory, do some editing and then send this to the server. Using the moveItem(at srcURL: URL, to dstURL: URL) throws file function it means the file is not duplicated and I only need to manage the persistence of the file in my documents directory not the temp directory additionally.

harmeet07
  • 501
  • 1
  • 5
  • 11