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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With