Hey fellow developers,
I’m developing an app that mounts network shares (SMB, AFP, Secure WebDAV, CIFS) using the NetFSMountURLAsync
function.
Recently, mounting WebDAV shares has stopped working — it fails with error code 22, but I can’t find a definitive reason for the failure. It simply doesn’t work. However, using Finder to connect to the same WebDAV share works flawlessly, so it doesn’t appear to be a server-side issue.
Strange Behavior
I’ve noticed something interesting:
If I create a new Xcode project and set Signing Certificate to Sign to Run Locally, the app mounts the WebDAV share without any issues. As soon as I change the signing option to anything else (e.g., Development), the share no longer mounts, and the app fails with error 22. Even if I switch back to Sign to Run Locally, the app remains broken and refuses to mount the share. Rebuilding the app, restarting Xcode, and clearing derived data/caches do not restore functionality. The only workaround I’ve found is to create a new Xcode project and copy the code over.
Additionally:
Mounting SMB and AFP shares always works without issues. The app is properly sandboxed. My certificates are valid until at least 2027. Granting the app Full Disk Access does not resolve the issue.
System Log Insights
Looking at the system log, I found several mounting-related messages. On failure, one stands out:
System Policy: webdavfs_agent() deny(1) file-mount <Path to the mount directory in the Documents directory of the example project>
Questions
Does anyone have any idea how to debug or resolve this issue? Is there a way to reset the example project to a working state? Are there any caches or system states I might have missed?
I’d prefer not to recreate all my certificates and configurations, as I don’t see any reason why they would affect only WebDAV mounting while everything else works fine.
Reproducing the Issue
I’ve created a minimal SwiftUI example to reproduce the problem. Just create a new macOS SwiftUI project, replace ContentView with my code, update the details to match your WebDAV share, and enable Outgoing Network Connections in the entitlements.
Any help or insights would be greatly appreciated!
Example Code
import SwiftUI
import NetFS
struct ContentView: View {
let mounter = WebDAVMounter()
var body: some View { VStack { Button("Test mount") { test() } } .padding() }
func test() { mounter.mount() }
}
class WebDAVMounter {
private var requestID: AsyncRequestID?
func mount() {
let username = <# username #>
let password = <#password#>
let serverURL = URL(string: "<#https://webfiles/Work~Home#>")!
let usedMountPoint = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let openOptions = NSMutableDictionary()
openOptions[kNAUIOptionKey] = kNAUIOptionNoUI
let mountOpts = NSMutableDictionary()
mountOpts[kNetFSSoftMountKey] = true
print("server URL: \(serverURL) usedMountPoint: \(usedMountPoint) username: \(username) password: \(password) sessionOpts: \(openOptions) mountOptions \(mountOpts)")
NetFSMountURLAsync(serverURL as CFURL,
usedMountPoint as CFURL,
username as CFString?,
password as CFString?,
openOptions as CFMutableDictionary,
mountOpts as CFMutableDictionary,
&requestID,
DispatchQueue.main,
{ status, asyncRequestId, mountedDirs in print("mount_report: \(status), mountedDirs: \(String(describing: mountedDirs))")})
}
}