Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode: Why is my event not being added to the calendar?

I have added the following code to my app:

NSDate * selected = [DatePicker date];
NSString * date = [selected description];

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit 
                                                              fromDate:DatePicker.date];

CalLabel1.text = [NSString stringWithFormat:@"%d", [components day]];

EKEventStore *store = [[EKEventStore alloc] init];

EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"Test Event";
//required
event.startDate = [DatePicker date];
event.endDate = [DatePicker date];
event.calendar = store.defaultCalendarForNewEvents;
//end

NSError *err;
[store saveEvent:event span:EKSpanThisEvent error:&err];

Why is this not adding anything to the iOS calendar?

Thanks.

like image 326
pixelbitlabs Avatar asked Oct 10 '11 20:10

pixelbitlabs


People also ask

Why is my Calendar widget not working?

Restart your device It's an easy and quick fix that only takes a minute or so. If you find Calendar not working, press and hold the power button on your device and tap the Restart option that appears on the screen. After the smartphone turns back on, open the Calendar app and check if the problem has been solved.

How do I automatically add events to my Apple Calendar?

Tap Mail, Contacts, Calendars. Scroll down and found Events Found in Mail. Toggle it on for automatic mail events added to Calendar app and off for manual input.

How do I show upcoming events on my iPhone Calendar widget?

On the lock screen of your iPhone or iPad, swipe left to right until you see a list of widgets. Scroll to the bottom and tap Edit. Tap Done. You should see upcoming events from your Calendar in the Today view.


1 Answers

Your event needs a valid time span to save it. Try this

event.startDate = selected;
event.endDate = [selected dateByAddingTimeInterval:30*60]; //30 minutes for example
like image 159
Joe Avatar answered Sep 28 '22 00:09

Joe