0

I need to send a file to the server. I select this file with UIViewControllerRepresentable which provides the url of the file and every time I try to upload I get the same message :- Domain=NSCocoaErrorDomain Code=257 "The file “example1.xml” couldn’t be opened because you don’t have permission to view it." . I think I need to add permissions on info.plist but I don't find the right one. If I select a file in the sandbox it works.

mahal tertin
  • 3,239
  • 24
  • 41
Vic
  • 1

1 Answers1

0

I solved it by using .startAccessingSecurityScopedResource () on the URL. Eg:

`var path = URL (string: "pathFile")!

//before reading the file

path.startAccessingSecurityScopedResource ()

//at the end

path.stopAccessingSecurityScopedResource ()

//to close. `

resources https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso

Vic
  • 1