LSRegisterURL resultCode -10819

I have an option in my app to set the URL Handler for smb or switch it back to Finder. But using my code below it always give me a -10819 error. Which is a generic kLSNotRegisteredErr, even those the documentation shows "Not currently used."

    func setDefaultHandler(bundleID: String) {
        DebugLogger.shared.log("Attempting to set \(bundleID) as default handler for SMB URLs")
        
        // Post Sonoma macOS requires user interaction to change default handlers
        // We'll register our app and then guide the user to System Settings
        
        // For our app, register it with Launch Services
        if bundleID != "com.apple.finder" {
            if let appBundleURL = Bundle.main.bundleURL as CFURL? {
                let registerResult = LSRegisterURL(appBundleURL, true)
                DebugLogger.shared.log("LSRegisterURL result: [\(appBundleURL)]\(registerResult)")
            }
        }
        
        // Check current handler using modern API
        let testSMBURL = URL(string: "smb://example.com")!
        if let handlerURL = NSWorkspace.shared.urlForApplication(toOpen: testSMBURL) {
            DebugLogger.shared.log("Current default handler is: \(handlerURL)")
            
            // Try to get the bundle ID from the URL
            var currentHandlerBundleID = ""
            if let bundle = Bundle(url: handlerURL) {
                if let handlerBundleID = bundle.bundleIdentifier {
                    currentHandlerBundleID = handlerBundleID
                    DebugLogger.shared.log("Current default handler bundle ID: \(handlerBundleID)")
                }
            }
            
            // Check if the current handler is already what we want
            let alreadySet = currentHandlerBundleID == bundleID
            DebugLogger.shared.log("Handler is already set correctly: \(alreadySet)")
            
            if alreadySet {
                let alert = NSAlert()
                alert.messageText = "Default Handler Status"
                alert.informativeText = "\(bundleID == "com.apple.finder" ? "Finder" : "LGN") is already set as the default handler for SMB URLs."
                alert.addButton(withTitle: "OK")
                alert.runModal()
            } else {
                // Guide the user to System Settings to change the handler
                promptToSetDefaultHandler(bundleID == "com.apple.finder" ? "Finder" : "LGN")
            }
        } else {
            DebugLogger.shared.log("Could not determine current handler")
            promptToSetDefaultHandler(bundleID == "com.apple.finder" ? "Finder" : "LGN")
        }
    }

Is your app sandboxed?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes it is.

Accepted Answer

OK, then I think you have bigger problems.

At one point we updated the sandbox to block attempts to change default URL scheme handlers. So, even if you get past this, I suspect that LSSetDefaultHandlerForURLScheme will fail [1].

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] I vaguely remember this failing with permErr, or -54, but…

Oh wow, some searching turned this up in a DTS case from 2018 (s. 701054199).

Understood, I can see what that was done.

LSRegisterURL resultCode -10819
 
 
Q