以下日志在保存新的日历事件后立即发送到控制台。
2017-08-27 09:07:42.853594-0400 Class Organizer Pro [1692:293239] eventEditViewController():日历已保存2017-08-27 09:07:42.929867-0400 Class Organizer Pro [1692:293642] XPC:错误 Domain = NSCocoaErrorDomain Code = 4099“指向服务的连接 com.apple.coreduetd.knowledge无效。“ UserInfo = {NSDebugDescription =指向服务的连接 com.apple.coreduetd.knowledge无效。} 2017-08-27 09:07:42.941417-0400 Class Organizer Pro [1692:293808]错误检索 来自CoreDuet流的siri触发器:错误 Domain = NSCocoaErrorDomain Code = 4099“指向服务的连接 com.apple.coreduetd.knowledge无效。“ UserInfo = {NSDebugDescription =指向服务的连接 com.apple.coreduetd.knowledge无效。} 2017-08-27 09:07:43.676386-0400 Class Organizer Pro [1692:293239] eventEditViewController()被解雇
@IBAction func setReminder() {
NSLog("setReminder()")
if (isAccessToEventStoreGranted) {
if (self.reminderAlreadyCreated == false) {
let myEventStore : EKEventStore = EKEventStore()
controller.eventStore = myEventStore
controller.editViewDelegate = self
// customize reminder/event
let earl : URL = URL.init(string: "https://" + StatusReportSettings.branchIOURI(Bundle.main.bundleIdentifier) + "/")!
controller.event?.url = earl
controller.event?.title = self.statusReportTitle.text!
controller.event?.notes = self.answerTextField.text!
self.present(controller, animated: true, completion: {
NSLog("setReminder() happened")
})
}
}
else {
let alertView : UIAlertController = UIAlertController.init(title: "Access Restricted", message: "This app doesn't have access to your reminders.", preferredStyle: UIAlertControllerStyle.alert)
alertView.show(self, sender: self)
}
}
func checkCalendarAuthorizationStatus() {
let status = EKEventStore.authorizationStatus(for: EKEntityType.event)
switch (status) {
case EKAuthorizationStatus.notDetermined:
// This happens on first-run
requestAccessToCalendar()
case EKAuthorizationStatus.authorized:
self.isAccessToEventStoreGranted = true
case EKAuthorizationStatus.restricted, EKAuthorizationStatus.denied:
self.isAccessToEventStoreGranted = false
requestAccessToCalendar()
}
}
func requestAccessToCalendar() {
eventStore.requestAccess(to: EKEntityType.event, completion: {
(accessGranted: Bool, error: Error?) in
if accessGranted == true {
DispatchQueue.main.async(execute: {
NSLog("requestAccessToCalendar() Access granted")
self.isAccessToEventStoreGranted = true
})
} else {
NSLog("requestAccessToCalendar() Access to store not granted")
self.isAccessToEventStoreGranted = false
} // end else
})
} // end requestAccessToCalendar
// Finishing an Edit
//
// func eventEditViewController(EKEventEditViewController, didCompleteWith: EKEventEditViewAction)
// Required. Invoked with the user is finished editing the event.
// Getting the Default Calendar
//
// func eventEditViewControllerDefaultCalendar(forNewEvents: EKEventEditViewController)
// Returns the calendar to use as the default calendar for new events.
// Constants
//
// EKEventEditViewAction
// Describes the action the user took to end editing.
func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction) {
NSLog("eventEditViewController()")
switch (action) {
case EKEventEditViewAction.saved:
NSLog("eventEditViewController(): Calendar saved")
self.reminderAlreadyCreated = true
case EKEventEditViewAction.cancelled:
NSLog("eventEditViewController(): Calendar cancelled")
self.reminderAlreadyCreated = false
case EKEventEditViewAction.deleted:
NSLog("eventEditViewController(): Calendar deleted")
self.reminderAlreadyCreated = false
}
controller.dismiss(animated: true, completion: {
NSLog("eventEditViewController() dismissed")
})
}
答案 0 :(得分:0)
你已经要求了:
let status = EKEventStore.authorizationStatus(for: EKEntityType.event)
但你需要这个:
let status = EKEventStore.authorizationStatus(for: EKEntityType.reminder)
提醒是一种与事件不同的实体类型。