objective c - iOS: Open a Calendar app New Event screen with populated date -
is possible redirect user calendar app new event screen programmatically populated start , end dates? aware of introduction calendars , reminders, seems overkill. have tried calshow://
, didn't seem work either or couldn't find correct scheme.
@import eventkit; @import eventkitui;
then present eventkit using this:
- (ibaction)scheduleclicked:(id)sender { ekeventstore *eventstore = [[ekeventstore alloc]init]; if([eventstore respondstoselector:@selector(requestaccesstoentitytype:completion:)]) { [eventstore requestaccesstoentitytype:ekentitytypeevent completion:^(bool granted,nserror* error){ if(!granted){ nsstring *message = @"hey! project can't access calendar... check privacy settings let in!"; dispatch_async(dispatch_get_main_queue(), ^{ // present alert warning. }); }else{ ekeventeditviewcontroller *addcontroller = [[ekeventeditviewcontroller alloc] initwithnibname:nil bundle:nil]; addcontroller.event = [self createevent:eventstore]; addcontroller.eventstore = eventstore; [self presentviewcontroller:addcontroller animated:yes completion:nil]; addcontroller.editviewdelegate = self; } }]; } }
meanwhile there delegates giving detail of end dates start date of calendar.
#pragma mark - eventeditdelegates - - (void)eventeditviewcontroller:(ekeventeditviewcontroller *)controller didcompletewithaction:(ekeventeditviewaction)action{ if (action ==ekeventeditviewactioncanceled) { [self dismissviewcontrolleranimated:yes completion:nil]; } if (action==ekeventeditviewactionsaved) { [self dismissviewcontrolleranimated:yes completion:nil]; } } #pragma mark - createevent - -(ekevent*)createevent:(ekeventstore*)eventstore{ ekevent *event = [ekevent eventwitheventstore:eventstore]; event.title = @"new event"; event.startdate = @"your start date"; event.enddate = @"your end date"; event.location=@"location"; event.allday = yes; event.notes =@"event description"; nsstring* calendarname = @"calendar"; ekcalendar* calendar; eksource* localsource; (eksource *source in eventstore.sources){ if (source.sourcetype == eksourcetypecaldav && [source.title isequaltostring:@"icloud"]){ localsource = source; break; } } if (localsource == nil){ (eksource *source in eventstore.sources){ if (source.sourcetype == eksourcetypelocal){ localsource = source; break; } } } calendar = [ekcalendar calendarforentitytype:ekentitytypeevent eventstore:eventstore]; calendar.source = localsource; calendar.title = calendarname; nserror* error; [eventstore savecalendar:calendar commit:yes error:&error]; return event; }
this createevent create new calendar
let me know if have more questions.
Comments
Post a Comment