-1

Besides browsing the Photolibrary I've enabled the Camera to add a photo to my

    @IBAction func startCameraButtonTapped(sender: AnyObject) {

    let startCameraController = UIImagePickerController()
    startCameraController.delegate = self
    startCameraController.sourceType = UIImagePickerControllerSourceType.Camera
    startCameraController.allowsEditing = true

    self.presentViewController(startCameraController, animated: true, completion: nil)
    //invoiceImageHolder.image!.scaleAndRotateImage2(280)
    //self.invoiceImageHolder.transform = CGAffineTransformMakeRotation((180.0 * CGFloat(M_PI)) / 180.0)

}

Every user input can be deleted, but now I'd like to know where the corresponding photo is. When I browse the photo library I can't see the photos taken with my app? Where are those photos stored?

[edit] This is my saveImage process

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage

    saveImage(selectedImage, path: fileInDocumentsDirectory("\(uniqueImageName)"))
    // set the unique image reference in textfield

    // Set photoImageView to display the selected image
    self.invoiceImageHolder.image = selectedImage

    // Dismiss the picker
    dismissViewControllerAnimated(true, completion: nil)

}

    func saveImage(image: UIImage, path: String) -> Bool{
    let pngImageData = UIImagePNGRepresentation(image)
    //        let jpgImageData = UIImageJPEGRepresentation(image, 1.0)
    let result = pngImageData?.writeToFile(path, atomically: true)
    //print("Save result \(result)")
    return result!
}

EDIT hmm I think I see where the photos are stored, but now how do I browse to them for deletions?

I think it's here:

/var/mobile/Containers/Data/Application/CBFE9E9D-A657-4011-8B9F-EF0C9BB2C603/Documents/

BUT everytime i restart the app the part between Application and /Documents is different??

enter image description here

Still not a working solution, but for those newbies as me this is a valuable readup: http://www.techotopia.com/index.php/Working_with_Directories_in_Swift_on_iOS_8

[EDIT 2] with this code i am able to see all whiles stored with my app. I was a bit surprise to see all the files

        // Files stored in my app filemanager

    let filemgr = NSFileManager.defaultManager()

    do {
        print("Start filemanager")
        let filelist = try  filemgr.contentsOfDirectoryAtPath(documentsDirectory())
        for filename in filelist {
            print(filename)
        }
    } catch {
        print("No directory path \(error)")
    }
    // end filemanager
alex
  • 4,804
  • 14
  • 51
  • 86

2 Answers2

1

UIImagePickerController() doesn't automatically save your photos into the library. See its UIImagePickerControllerDelegate protocol and you'll see that it has a method returning your UIImage after making a photo. Then you can save it:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
    }
}
katleta3000
  • 2,484
  • 1
  • 18
  • 23
0

you save them - not in the photo library - but as 'simply' files inside your app's documents folder. There is no standard UI for deletion then.

You need to write your own ViewController to show & handle deletions then.

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • hmm didn't realise that. Is it correct that the id of my app (the part between Application and Documents) is always different? I don't see how i can get inside my app's documents folder, if that is the case. When i delete my app from my phone are all the files in folder Documents also deleted??? – alex Oct 23 '15 at 09:12
  • Yes and yes. The alert shown by iOS states this clearly: ‘Deleting “app name” will also delete all of its data.’ – Douglas Hill Oct 23 '15 at 11:55