Pat*_*ckR 9 macos xcode ekeventstore swift
这看起来非常简单,但我已经挣扎了几天才能访问OSX上的日历.我已经打开了App Sandbox功能,并在App Data中勾选了"日历"框.我用以下视图控制器类创建了非常简单的应用程序:
import Cocoa
import EventKit
class ViewController: NSViewController {
var eventControl = EKEventStore()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我添加的唯一代码行是导入EventKit并初始化eventControl.
当我在调试中运行它时,我在eventControl初始化行中收到错误
2016-10-28 15:02:00.056521 calendarTest[4105:847101] CoreData: XPC: Unable to load metadata: Error Domain=NSCocoaErrorDomain Code=134070 "An error occurred in the persistent store." UserInfo={Problem=request failed, insufficient permission}
2016-10-28 15:02:00.057742 calendarTest[4105:847101] [error] error: -addPersistentStoreWithType:NSXPCStore configuration:(null) URL:file:///Users/patrickramsden/Library/Calendars/Calendar%20Cache options:{
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
agentOrDaemon = 1;
serviceName = "com.apple.CalendarAgent.database";
} ... returned error Error Domain=NSCocoaErrorDomain Code=134070 "An error occurred in the persistent store." UserInfo={Problem=request failed, insufficient permission} with userInfo dictionary {
Problem = "request failed, insufficient permission";
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何获得正确的权限.
我正在使用Xcode 8.1和macOS Sierra 10.12.1
您需要在info.plist中添加使用说明.这是对您需要访问提供给用户的服务的原因的一个小描述.
<key>NSCalendarsUsageDescription</key>
<string>Description of why you need access to the Calendar</string>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1009 次 |
最近记录: |