Hey,
This is my code. I have the url of the smb server which I have connected in the 'Files' app. It finds the file on the server, but I always says that it has no permission to read it. On my server I have allowed everyone to read and write. Do I need to write something in my code that my app knows that it has permission to read ?
let url: URL = URL(fileURLWithPath: "/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/xVUdQwTestApp/testaufbau.csv")
do
{
let fileURLs = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
Admin.fileContent = try String(contentsOf: fileURLs[0], encoding: .utf8)
print("ADMIN: \(Admin.fileContent)")
}
catch
{
print(error)
}
Thank you for all the help
Regards,
Tell Tobler
If you have a security-scoped URL, you must bracket your actual file system access with
startAccessingSecurityScopedResource()
and
stopAccessingSecurityScopedResource()
If you want to persist access to that URL, you must use a security-scoped bookmark. For example, to get a bookmark to save:
let bookmark = try url.bookmarkData(options: [.withSecurityScope], includingResourceValuesForKeys: nil, relativeTo: nil)
And to get a URL from that bookmark:
var isStale = false
let resolvedURL = try URL(resolvingBookmarkData: bookmark, options: [.withSecurityScope], relativeTo: nil, bookmarkDataIsStale: &isStale)
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"