I am saving a movie file in an iOS documents directory. The file is saved fine and I can access and play it after it has been saved. But when I rebuild the project I can't access the file, when I have checked the urls the application parent directory has changed.
Original saved url file:///var/mobile/Containers/Data/Application/AB91D495-0AB4-4182-89D5-A124F748D474/Documents/BD1034BA-08BF-4F5D-813E-722C1FF9EC41/1F25B1B6-A05B-4178-8983-16C14AB8F263.mov
url from a file saved after the project has been built again file:///var/mobile/Containers/Data/Application/52EE7C76-88EA-42CC-965F-F9CD977825C0/Documents/C634D4E1-DB3C-4052-A7F5-0BFCF6EB3752/E68BDB15-6CB0-446B-893C-488839438588.mov
Will this happen between app store updates or will the OS handle it? Surley if the user were to saved data inside this directory, If I do an app store update will the OS copy the data or not change the parent folder path?
The code I am using to save the movie files, for context this moves the files from the temporary directory to a newly created directory without any issues.
private func moveFileToNewDirectory(_ movieFileTempDirectory: URL) -> URL? {
let fileManager = FileManager.default
let directoryUUID = UUID()
do {
/// Get the documents directory URL
let documentsURL = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
/// Create a new directory URL inside the documents directory
let directoryURL = documentsURL.appendingPathComponent(directoryUUID.uuidString, isDirectory: true)
/// Check to make sure its empty, we've just made it do it should be
guard !fileManager.fileExists(atPath: directoryURL.path()) else { return nil }
/// Create the new directory
try fileManager.createDirectory(atPath: directoryURL.path(), withIntermediateDirectories: true, attributes: nil)
/// Create a new destination URL appended with the movieOutputFile filename
let destinationURL = directoryURL.appendingPathComponent(movieFileTempDirectory.lastPathComponent, isDirectory: false)
/// Set the attributes - not sure if we need to do this yet
//let attributes: [FileAttributeKey: Any] = [.protectionKey: FileProtectionType.complete]
//try fileManager.setAttributes(attributes, ofItemAtPath: path)
try fileManager.moveItem(atPath: movieFileTempDirectory.path(), toPath: destinationURL.path())
return destinationURL
} catch let error {
print(error.localizedDescription)
return nil
}
}