cocoa - Swift 中的 FSMountServerVolumeSync 发生了什么?

标签 cocoa swift xcode6 osx-yosemite

我正在尝试找到一种在我正在创建的 Cocoa 应用程序中挂载 SMB 共享的方法,但是所有文档都指向 FSMountServerVolumeSync,但是当我将其放入代码中时,我收到错误

'FSMountServerVolumeSync' is unavailable: APIs deprecated as of OS X 10.9 and earlier are unavailable in Swift

我发现了一些有关旧替代方案 - DADiskMount 的信息,但我不知道这是否是合适的替代方案,也不知道如何实现它。

现在是否有一种 Swift 方式来挂载适用于最新版本 Swift 的 SMB 共享?

最佳答案

因此,对于任何寻找此问题答案的人来说,Apple 似乎没有提供任何相关文档,但经过大量搜索后,我发现 NetFS.framework 仍然非常有效并希望得到支持。

当我将 NetFS 框架包含到 Swift 文件中并进行尝试后,一切都按预期工作。

include Coco
include NetFS    

func mountShare( serverAddress: String, shareName: String, userName: String, password: String) {
    let fm = NSFileManager.defaultManager()
    let mountPoint = "/Volumes/".stringByAppendingString(shareName)
    var isDir : ObjCBool = false
    if fm.fileExistsAtPath(mountPoint, isDirectory:&isDir) {
        if isDir {
            unmount(mountPoint, 0)
            println("unmount \(mountPoint)")
        }
    }
    let sharePath = NSURL(string: "\(serverAddress)/\(shareName)")!
    let mounted: Int32 = NetFSMountURLSync(sharePath, nil, userName, self.decodeStr(password), nil, nil, nil)
    if mounted > 0 {
        println("Error: sharePath: \(sharePath) Not Valid")
    } else {
        println("Mounted: \(sharePath)")
    }
}

关于cocoa - Swift 中的 FSMountServerVolumeSync 发生了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29046397/

相关文章:

ios - 如何在 Xcode 运行脚本中 cd 到工作目录?

iphone - 如何缩放覆盖 View 下方的 MapView 注释?

objective-c - 使自动完成不区分大小写

cocoa - 使用 NSBezierPath 时切换线条属性

ios - 解析查询 .whereKey

ios - 我们能否像 android asyncTask 一样显示加载状态,直到我们在快速使用 HTTP Post 请求时得到响应

objective-c - 将方法的所有参数传递到 NSLog

swift - 用类型别名注释整个函数声明

ios - Swift drawInRect 无法展开 Optional.None

ios - RPSCommonObjects.m 解析问题未知类型名称 NSString