iphone - iOS: EKEventStore sources / defaultCalendarForNewEvents / calendarsForEntityType all return nothing AFTER authorization -


i have app trying out door. code written ios5 in mind team. added requestaccesstoentitytype:completion: call runs successfully. however, after being granted access, no sources / defaultcalendar or calendars based on entity. , cannot create new calendar.

when calling defaultcalendarfornewevents error

error domain=ekcaderrordomain code=1013 "the operation couldn’t completed. (ekcaderrordomain error 1013.)" , result nil.

if out of viewcontroller trying , go in, works fine. if, after getting alert no source, keep trying (without backing out viewcontroller), repeatedly fails.

i want stress, authorization call works (the user asked access calendars , gives it, , later calls confirm authorization pass). other questions have found similar have solution -- making sure requestaccesstoentitytype

[eventstore requestaccesstoentitytype:ekentitytypeevent completion:^(bool granted, nserror *error) {     if (granted)         {        //[self performselectoronmainthread:@selector(doscheduleactivity:) withobject:activity waituntildone:yes];            dispatch_async(dispatch_get_main_queue(), ^{                 [self doscheduleactivity:activity];                 });            }        else        { // should force main thread          dispatch_async(dispatch_get_main_queue(), ^{             uialertview *av = [[uialertview alloc] initwithtitle:@"calendar access required" message:@"in order schedule activities, app needs access calendar.  can change in device settings." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil];             [av show];             });          }  }] ; 

granted comes true , [self doscheduleactivity: gets called. following code function called @ beginning of routine , failures are.

ekcalendar *sacalendar; eksource *source; nserror *error; uialertview *alert;  logdebug(@"eventstore defaultcalendar %@", [eventstore defaultcalendarfornewevents]);  // validate access calendar prior segueing if ([ekeventstore respondstoselector:@selector(authorizationstatusforentitytype:)]) {     switch([ekeventstore authorizationstatusforentitytype:ekentitytypeevent])     {         case ekauthorizationstatusauthorized:             break;         case ekauthorizationstatusnotdetermined:             {                 dispatch_async(dispatch_get_main_queue(), ^{                     uialertview *alert = [[uialertview alloc] initwithtitle:sa_alert_caption_calendar_access_not_determined message:sa_alert_body_calendar_access_not_determined delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil];                     [alert show];                     });                 return false;                 }         case ekauthorizationstatusdenied:             {                 dispatch_async(dispatch_get_main_queue(), ^{                     uialertview *alert = [[uialertview alloc] initwithtitle:sa_alert_caption_calendar_access_denied message:sa_alert_body_calendar_access_denied delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil];                     [alert show];                     });                 return false;                 }         case ekauthorizationstatusrestricted:             {                 dispatch_async(dispatch_get_main_queue(), ^{                     uialertview *alert = [[uialertview alloc] initwithtitle:sa_alert_caption_calendar_access_restricted message:sa_alert_body_calendar_access_restricted delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil];                     [alert show];                     });                 return false;                 }         default:             break;     } }  // search application specifc calendar.. sacalendar = nil; for(ekcalendar *calendar in [eventstore calendarsforentitytype:ekentitytypeevent]) {     if([calendar.title isequaltostring:sa_activities_calendar_title])     {         sacalendar = calendar;         break;     } } // ..and create scratch if nonexistent if(nil == sacalendar) {     // find local source hook new calendar     for(source in [eventstore sources])     {         if(source.sourcetype == eksourcetypelocal)         {             break;         }     }      // if not find local source type, wrong     if( source == nil || source.sourcetype != eksourcetypelocal)     {         alert = [[uialertview alloc] initwithtitle:sa_alert_caption_calendar_error_no_source message:sa_alert_body_calendar_error delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];         [alert show];         return false;     }      // create calendar applcation, name it, color , assign source     sacalendar = [ekcalendar calendarforentitytype:ekentitytypeevent eventstore:eventstore];     [sacalendar setsource:source];     [sacalendar settitle:sa_activities_calendar_title];     [sacalendar setcgcolor:[[uicolor yellowcolor] cgcolor]];      // create     error = nil;      if(![eventstore savecalendar:sacalendar commit:true error:&error])     {         dispatch_async(dispatch_get_main_queue(), ^{             uialertview *alert = [[uialertview alloc] initwithtitle:sa_alert_caption_calendar_error_cant_save message:sa_alert_body_calendar_error delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];             [alert show];             });         return false;     } }  return true; 

everything comes nil though authorized , check in [ekeventstore authorizationstatusforentity:ekentitytype returns ekauthorizationstatusauthorized

after failure here, if out of view controller , go in, works. happens first time when system asks user calendar access , reply ok.

thanks insight. i've been stepping through debugger, , doing printf type debugging avoid sort of timing issues, etc. , see nothing contrary event stuff have looked on apple site.

my target device 6.1.3 iphone 5

ok, turns out there small line of code in viewdidload before [eventstore requestaccesstoentitytype:ekentitytypeevent completion:^(bool granted, nserror *error code , tried access eventstore. superfluous , did not need happening , had not noticed it. once removed code stuff works, go needing authorize, after authorization, eventstore "bad" due previous access.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -