我想在我的swift應用程序中設置一個簡單的EKReminder,以提醒用戶趕上公交車。但是,當我嘗試保存我的提醒時,我總是收到一個錯誤消息(沒有錯誤報告,應用程序崩潰)。我有下面的代碼。在iOS中設置提醒Swift
public class func createReminder(reminderTitle: String, timeInterval: NSDate) {
var calendarDatabase = EKEventStore()
calendarDatabase.requestAccessToEntityType(EKEntityTypeReminder,
completion: nil)
let reminder = EKReminder(eventStore: calendarDatabase)
reminder.title = reminderTitle
let alarm = EKAlarm(absoluteDate: timeInterval)
reminder.addAlarm(alarm)
reminder.calendar = calendarDatabase.defaultCalendarForNewReminders()
var error: NSError?
calendarDatabase.saveReminder(reminder, commit: true, error: &error)
}