In an iOS app, I’m making an attempt to load a .csv file from the person iCloud Drive. It really works as anticipated within the simulator however doesn’t work on a tool. I’ve seen a few SO articles with related questions however no resolution that works for me.
This Apple documentation appears to point that I’m coding the method accurately: https://developer.apple.com/documentation/swiftui/view/fileimporter(ispresented:allowedcontenttypes:allowsmultipleselection:oncompletion:)
I believed maybe an Information.plist merchandise was required, however I couldn’t discover any keys that appear to repair this.
The outcome is identical whether or not I embody the url.startAccessingSecurityScopedResource()
line or not.
The console says: Did not import CSV: The file “EightItems.csv” couldn’t be opened since you don’t have permission to view it.
The dataStore merchandise beneath is simply to manage a progress view:
@Printed var isImporting: Bool = false
And the code is:
@State non-public var isDocumentPickerPresented = false
//import from csv file
if dataStore.isImporting {
ProgressView("Importing information...")
} else {
Button("Import CSV") {
isDocumentPickerPresented = true
}
.fileImporter(
isPresented: $isDocumentPickerPresented,
allowedContentTypes: [.commaSeparatedText],
allowsMultipleSelection: false
) { end in
swap outcome {
case .success(let urls):
if let url = urls.first {
let gotAccess = url.startAccessingSecurityScopedResource()
if !gotAccess { return }
dataStore.importCSV(from: url, context: context)
url.stopAccessingSecurityScopedResource()
}
case .failure(let error):
print("Failed to select file: (error.localizedDescription)")
}
}
.buttonStyle(.borderedProminent)
}//if else
Any steerage could be appreciated. Xcode 15.4, iOS 17.5