在Mac OS X中加載mediaSources
屬性時出現錯誤。
我試圖使用MLMediaLibrary
類獲取Apple Photos源。
我的應用程序是沙盒,並具有圖片文件夾的只讀權限。
我發現了錯誤:在MLMediaLibrary中加載媒體源時出錯
MLMediaLibrary error obtaining remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.MediaLibraryService" UserInfo={NSDebugDescription=connection to service named 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
}
}
順便說一句 - 也嘗試沒有沙箱,結果相同。 –