Alarm example in calender
Solution:
In default Calender you can schedule the events by EKEvent and EKAlarm.The below is an example for which you can set an alarm from today to next three days at your current time.I added 30 seconds buffer time for that you can test it easily.
Example:
In default Calender you can schedule the events by EKEvent and EKAlarm.The below is an example for which you can set an alarm from today to next three days at your current time.I added 30 seconds buffer time for that you can test it easily.
Example:
import UIKit
import EventKit
class ViewController: UIViewController {
var yourReminderCalendar: EKCalendar?
override func viewDidLoad() {
super.viewDidLoad()
var eventDB = EKEventStore.init()
// Request access to calendar first
eventDB.requestAccess(to: .event, completion: { (granted, error) in
if granted {
var event = EKEvent.init(eventStore: eventDB)
event.title = "New Event"
event.startDate = Date()
let end = NSCalendar.current.date(byAdding: .day, value: 3, to: Date()); event.endDate = end
event.isAllDay = true
event.calendar = eventDB.defaultCalendarForNewEvents
let alarm = EKAlarm(absoluteDate:Date().addingTimeInterval(30))
event.addAlarm(alarm)
do {
try eventDB.save(event, span: .thisEvent)
} catch let error as NSError {
print("failed to save event with error : \(error)")
}
}
else
{
print("calendar not allowed")
}}
)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Comments
Post a Comment