2

Below are the two functions which I use in the picker view controller to save the file in the App documents directory. And save the url in the local DB & display the image using UIImage(contentsOfFile: ImagePathString)

Everything works well as until this point however as soon as i re-run the simulator images does not show up. I believe its because the app directory keeps changing every time its run on the simulator. My question if its the same when deployed on the device?

 func getDocumentsDirectory() -> NSString {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentsDirectory = paths[0]
    return documentsDirectory
}

    //Below function is used in imagePickerController

    if let data = UIImagePNGRepresentation(modifiedImage!) {
        let filename = getDocumentsDirectory().stringByAppendingPathComponent("\(NSDate()).png")
        data.writeToFile(filename, atomically: true)
        pathImage = filename
        print(pathImage)
    }
Kanan Jarrus
  • 607
  • 1
  • 12
  • 26

1 Answers1

4

Yes url to App documents folder may change when the app is deployed on the device. Refer below link Technical Note TN2406 .

Payal Maniyar
  • 4,293
  • 3
  • 25
  • 51