我正在尝试通过Xcode 11.2.1中使用Swift 5开发的Mac应用程序将日历事件添加到macOS日历中。
首先,我在“应用程序沙箱”中选中了“日历”权利。
我正在尝试提示这样的权限:
import EventKit
@IBAction func clickAddToCalendar(_ sender: NSButton){
let eventStore = EKEventStore()
eventStore.requestAccess(to: .event){ granted, error in
print(granted) // returns false
print("----")
print(error) // returns nil
}
}
......但granted
就是false
每次和我从来没有看到一个弹出授予权限。在macOS上是否需要这样的访问提示?看起来是这样,因为当我尝试直接像这样添加日历事件时:
let event = EKEvent(eventStore: eventStore)
event.title = "My Event"
event.startDate = Date()
event.endDate = Date()
event.calendar = eventStore.defaultCalendarForNewEvents
do {
try eventStore.save(event, span: .thisEvent)
} catch let error as NSError {
print(error)
}
...我得到一个错误:
serviceName =“ com.apple.CalendarAgent.database”; ...使用userInfo字典返回错误NSCocoaErrorDomain(134070){问题=“请求失败,权限不足”}
有没有人这样做可以给我一些指导?谢谢!
您是否有“隐私-日历使用说明”的info.plist项目?
EventKit必需的请参阅https://developer.apple.com/documentation/eventkit/accessing_the_event_store
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句