I cannot seem to edit the original post but based on @OOPer's suggestion to retry the startAccessingSecurityScopedResource method I was able to get this working. Adding my code here as an example for anyone that may find this useful. Thank you @OOPer and @Claude31.
.fileImporter(isPresented: $isImporting, allowedContentTypes: [.zip], allowsMultipleSelection: false
) { result in
do {
guard let selectedFile: URL = try result.get().first else { return }
if selectedFile.startAccessingSecurityScopedResource() {
guard let dest = moveZip(sourceUrl: selectedFile) else { print("Error")
return
}
self.dfuFile = dest
selectedFile.stopAccessingSecurityScopedResource()
}
self.dfuFirmware = DFUFirmware(urlToZipFile: self.dfuFile, type: DFUFirmwareType.application)
self.dfuActive = true
} catch {
// Handle the Failure
print("Unable to read file")
print(error.localizedDescription)
}
}
Topic:
Programming Languages
SubTopic:
Swift
Tags: