我在加载时遇到错误mediaSources
Mac OS X 中的属性。
我正在尝试使用以下方法获取 Apple Photos 源MLMediaLibrary
class.
我的应用程序是沙盒的,并且具有图片文件夹的只读权限。
我收到错误:
MLMediaLibrary 获取远程对象代理时出错:错误 Domain=NSCocoaErrorDomain Code=4097“连接到名为 com.apple.MediaLibraryService 的服务”UserInfo={NSDebugDescription=连接到名为 com.apple.MediaLibraryService 的服务}
据我所知,错误 4097 是连接中断。
我对 Swift 不太熟悉,但我确实使用 Objective C 运行了完全相同的测试并得到了相同的结果。
我的猜测是我错过了某种权利。
这是我的(非常简化的)代码:
import Foundation
import MediaLibrary
public class MediaLibrary : NSObject{
var library : MLMediaLibrary!
private func loadSources(){
if let mediaSources = library.mediaSources {
for (ident, source) in mediaSources{
print("Identifier: \(ident)");
}
}
}
public override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
loadSources()
}
public override init(){
super.init()
let options : [String : AnyObject] = [MLMediaLoadSourceTypesKey : MLMediaSourceType.Image.rawValue, MLMediaLoadIncludeSourcesKey : MLMediaSourcePhotosIdentifier]
library = MLMediaLibrary(options: options)
library.addObserver(self, forKeyPath: "mediaSource", options: NSKeyValueObservingOptions.New, context: nil)
library.mediaSources; // trigger load, status will be reported back in observeValueForKeyPath
}
}
结果发现有两件事不对劲:
1. The MLMediaLoadIncludeSourcesKey
应该指向一个字符串数组,而不是单个字符串
2.观察关键路径错误,应该是"mediaSources"
,缺少一个s
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)