使用cocoa和objective-c在Xcode中安装SMB驱动器

And*_*oig 0 xcode cocoa netfs

我正在尝试构建一个小应用程序来登录SMB网络驱动器,但我无法做任何工作来进行实际连接.任何人都有使用NetFSMountURLAsync的经验吗?或者甚至更好,一个例子?

Jer*_*ope 7

如果您遇到问题,我会从同步版本开始:

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)
Run Code Online (Sandbox Code Playgroud)

如果你想使用默认挂载点,也可以在那里传递nil.

NetFSMountURLSync(serverPath, nil, nil, nil, nil, mountOptions, nil)
Run Code Online (Sandbox Code Playgroud)

真的它应该工作,即使你只传入serverPath.我只包含了mountOptions,所以你有一个例子,如果你需要设置任何.

NetFSMountURLSync(serverPath, nil, nil, nil, nil, nil, nil)
Run Code Online (Sandbox Code Playgroud)

第3和第4个参数是user和pass,如果您不希望操作系统处理该部分,则可以提供该参数.