Mount SMB drive in Xcode using cocoa and objective-c

3.9k Views Asked by At

I am trying to build a little app to log into an SMB network drive, but I can't get anything to work for doing the actual connecting. Anyone have any experience with NetFSMountURLAsync? Or even better, an example?

1

There are 1 best solutions below

6
Jeremy Pope On BEST ANSWER

If you are having trouble, I'd start with the Sync version:

let serverPath = NSURL(string: "smb://yourserverpath/share")! as CFURL
let mountPath = NSURL(string: "/localmountpointyouwanttouse_shouldalreadyexist_ifnot_create_it_before")! as CFURL
let mountOptions = NSMutableDictionary(dictionary: ["MountAtMountDir": false]) as CFMutableDictionaryRef
NetFSMountURLSync(serverPath, mountPath, nil, nil, nil, mountOptions, nil)

if you want to use the default mount point, just pass nil in there as well.

NetFSMountURLSync(serverPath, nil, nil, nil, nil, mountOptions, nil)

really it should work even if you only pass in the serverPath. I only included the mountOptions so you have an example if you needed to set any.

NetFSMountURLSync(serverPath, nil, nil, nil, nil, nil, nil)

The 3rd and 4th arguments are user and pass, which you can supply if you don't want the OS to handle that part.