Piero
Piero

Reputation: 9273

How set no alarm in EKEvent in calendar

when i create a new EKEvent for a calendar i notice that automatically add an alarm ad 9 of the event day, how i can set no alarm? i have tried in this way:

EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.titile = @"This is an event";
event.calendar = calendar;
event.alarms = nil; //in this way don't work...

but don't works, and in the calendar i see the alarm how u can see:

enter image description here

anyone knows how i can add EKEvent without alarm?

Upvotes: 4

Views: 1425

Answers (6)

Stephan Januar
Stephan Januar

Reputation: 156

The only way for me is removing it manually from the event just after creation:

private func CreateEntry(calendar : EKCalendar, date: Date, prop: String) {

    let event:EKEvent = EKEvent(eventStore: eventStore)

    event.title = prop
    event.startDate = date
    event.endDate = date
    event.isAllDay = true
    event.notes = prop
    event.calendar = calendar //eventStore.defaultCalendarForNewEvents

    if event.alarms != nil {
        for del in event.alarms! {
            event.removeAlarm(del)
        }
    }

    do {
        try eventStore.save(event, span: EKSpan.thisEvent, commit: true)
    } catch let error as NSError {
        print("failed to save event with error : \(error)")
    }
}

Upvotes: 1

stefat
stefat

Reputation: 154

Issue solved at my experience. It depends, in the device, not in the simulator, by Settings/Mail,Contacts,Calendars/Default Alert Times/Events Setup. If set to None you can add an alert or leave it as per the default, i.e. nil. It works. If set to anything else, this overwrites any setup you make to the event alarm, nil included.

Upvotes: 0

jold
jold

Reputation: 152

It looks like only way to disable alarm is to create one in distant future using the following code

EKAlarm * alarm = [EKAlarm alarmWithAbsoluteDate:[NSDate distantFuture]];
event.alarms = @[alarm];

Hope this helps.

Upvotes: 1

fisher
fisher

Reputation: 1296

I have finally found the reason for why some of us gets an alarm when creating new EKEvents event though we have specified alarms off. For me, and I'm guessing for most of you, the selected calendar is a google calendar. Google calendar has a setting where it creates an alarm for every new event added. To turn it off, log on to your google calendar on a web browser to turn it off. I hope this will save some frustration! Brgds, Erik

Upvotes: 1

G-Power
G-Power

Reputation: 149

I found that default alarm is set by Settings.app of Calendar settings. I don't find a right way to setup an event without alarm if default alarm is set in settings.app.

Upvotes: 1

holex
holex

Reputation: 24041

you should set an empty NSArray with no alarms, like this:

EKEvent *event = // whatever...
[event setAlarms:[NSArray array]];

Upvotes: 1

Related Questions