When I tap a file my app supports in the iOS file manger, my apps delegate method
private func open(url: URL, options: [UIApplication.OpenURLOptionsKey : Any]?)->Bool
gets called, where I read the file
do {
try fileData = Data(contentsOf: url)
}
catch {
print(error.localizedDescription)
}
which gives an error 257 (not authorised). When accessing the same file using the document picker :
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt URL: URL) {
if controller.documentPickerMode == UIDocumentPickerMode.import {
var fileData : Data
do {
try fileData = Data(contentsOf: URL)
}
catch {
print(error.localizedDescription)
}
}
everything works fine. I get a data object which I can use. One thing I noticed is that the AppDelegate method gets an URL in the form of
/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Downloads/filename
while the documentPicker callback gets
/private/var/mobile/Containers/Data/Application/7A30D4D7-BD7D-4051-B3DE-143E18F48B23/tmp/myAppIndentifier-Inbox/filename
Adding - as suggested here -
let result = url.startAccessingSecurityScopedResource()
did not make a difference. My "Supports opening documents in place" plist key is set to TRUE. Anyone any idea?