Cannot find my downloaded file in the document fol

2019-09-02 08:42发布

问题:

I'm facing an issue when trying to read my downloaded audio file from the document folder. The file '032000.mp3' really exists on the download folder(see illustration)

  F501141C-4D7B-42D9-83DE-83DE0C04AA66
  |- Documents
  |-- audios
  |--- 0
  |---- 032
  |------ 032000.mp3


  var path: String = "/Users/abm/Library/Developer/CoreSimulator/Devices/52FDA0EC-1A3F-4A69-9359-96511E21E172/data/Containers/Data/Application/F501141C-4D7B-42D9-83DE-83DE0C04AA66/Documents/audios/0/032/032000.mp3"
  println("fileExistsAtPath= \(NSFileManager.defaultManager().fileExistsAtPath(path))") // --> false

Note: Opening the downloaded file via terminal just works.

Thanks in advance

回答1:

You need to get path for documents folder dynamically. Every times, when you start application in simulator, application folder name changed. See this answer How to find NSDocumentDirectory in swift?



标签: ios xcode swift