On macOS, the Finder allows to connect to a server and store the login credentials. When creating a bookmark to a file on a server and resolving it again, the server is mounted automatically (unless I provide the option URL.BookmarkResolutionOptions.withoutMounting
).
I just tried connecting to my Mac from my iPad via SMB in the Files app and storing a bookmark to a file on the server, but disconnecting the server and trying to resolve the bookmark throws the error (I translated the English text from Italian):
Error Domain=NSFileProviderErrorDomain Code=-2001 "No file provider was found with the identifier "com.apple.SMBClientProvider.FileProvider"'" UserInfo={NSLocalizedDescription=No file provider was found with the identifier "com.apple.SMBClientProvider.FileProvider"., NSUnderlyingError=0x302a1a340 {Error Domain=NSFileProviderErrorDomain Code=-2013 "(null) "}}
Every time I disconnect and reconnect to the server, selecting the same file returns a different path. The first time I got
/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/WtFD3Ausername/path/to/file.txt
The next time WtFD3A
changed to EqHc2g
and so on.
Is it not possible to automatically mount a server when resolving a bookmark on iOS?
The following code allows to reproduce the issue:
struct ContentView: View {
@State private var isPresentingFilePicker = false
@AppStorage("bookmarkData") private var bookmarkData: Data?
@State private var url: URL?
@State private var stale = false
@State private var error: Error?
var body: some View {
VStack {
Button("Open") {
isPresentingFilePicker = true
}
if let url = url {
Text(url.path)
} else if bookmarkData != nil {
Text("couldn't resolve bookmark data")
} else {
Text("no bookmark data")
}
if stale {
Text("bookmark is stale")
}
if let error = error {
Text("\(error)")
.foregroundStyle(.red)
}
}
.padding()
.fileImporter(isPresented: $isPresentingFilePicker, allowedContentTypes: [.data]) { result in
do {
let url = try result.get()
if url.startAccessingSecurityScopedResource() {
bookmarkData = try url.bookmarkData()
}
} catch {
self.error = error
}
}
.onChange(of: bookmarkData, initial: true) { _, bookmarkData in
if let bookmarkData = bookmarkData {
do {
url = try URL(resolvingBookmarkData: bookmarkData, bookmarkDataIsStale: &stale)
} catch {
self.error = error
}
}
}
}
}