在MLMediaLibrary中加载媒体源时出错

Mos*_*ieb 5

mediaSources在Mac OS X中加载属性时遇到错误.
我正在尝试使用MLMediaLibrary该类获取Apple Photos源代码.
我的应用程序是沙盒,并具有图片文件夹的只读权限.
我收到错误:

MLMediaLibrary错误获取远程对象代理:错误域= NSCocoaErrorDomain代码= 4097"连接到名为com.apple.MediaLibraryService的服务"UserInfo = {NSDebugDescription =连接到名为com.apple.MediaLibraryService的服务}

根据我的收集,错误4097是连接中断.
我对Swift不是很熟悉,但我确实使用目标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
    }
}
Run Code Online (Sandbox Code Playgroud)

Mos*_*ieb 4

原来有两件事不对:
1.MLMediaLoadIncludeSourcesKey应该指向一个字符串数组,而不是单个字符串
2.观察键路径错误,应该是"mediaSources",错过了s