xcode - 使用 cocoa 和 Objective-c 在 Xcode 中挂载 SMB 驱动器

标签 xcode cocoa netfs

我正在尝试构建一个小应用程序来登录 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/

相关文章:

xcode - 我的 Sparkle appcast 需要闪光吗 :dsaSignature field in order to be valid?

ios - xcode 构建失败,并从 : "_RCTSetLogFunction", o 引用 : -[AppTests testRendersWelcomeScreen] in AppTests.

xcode - 如何在 NSCollectionView 中创建组?

objective-c - 链接到 PostgreSQL 和 SSL

iphone - 具有额外 ivar 和方法的核心数据管理对象

swift - 在 Swift 中异步挂载卷

iOS 8.1.3 - 企业分发 - 应用程序缺少应用程序标识符授权

Objective-C:将字符串与 if() 值进行比较在 [NSMutableArray objectatindex:] 上不起作用