我正在尝试构建一个小应用程序来登录 SMB 网络驱动器,但我无法进行任何实际连接。有人有 NetFSMountURLAsync 的经验吗?或者更好,举个例子?
最佳答案
如果您遇到问题,我会从同步版本开始:
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)
如果您想使用默认挂载点,也只需在其中传递 nil 即可。
NetFSMountURLSync(serverPath, nil, nil, nil, nil, mountOptions, nil)
实际上,即使您只传入 serverPath,它也应该可以工作。我只包含了 mountOptions,因此如果您需要设置任何选项,您可以有一个示例。
NetFSMountURLSync(serverPath, nil, nil, nil, nil, nil, nil)
第三个和第四个参数是用户和通行证,如果您不希望操作系统处理该部分,则可以提供它们。
关于xcode - 使用 cocoa 和 Objective-c 在 Xcode 中挂载 SMB 驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28100736/