saveEvent возвращается Календарь не установлен

Я пытаюсь сохранить событие в календаре из своего приложения. Мой код работает для iOS 7, но на iOS 6 он возвращает Календарь не установлен.

Приложение предлагает пользователю предоставить доступ к календарю на iOS 7. Но такой запрос не появляется для iOS 6. Хотя приложению предоставляется доступ в Настройки-> Конфиденциальность -> Календарь.

И да, я уже реализовал requestAccessToEntityType:completion:.

Вот мой фрагмент кода.

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

if ([objStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
    // iOS 6 and later
    [objStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (granted)
        {
            // code here for when the user allows your app to access the calendar
            EKEvent *calEvent = [EKEvent eventWithEventStore:objStore];
            calEvent.title = mstrTitleEvent;
            calEvent.startDate = self.dateToBeSet;
            calEvent.endDate = self.dateToBeSet;
            calEvent.calendar = objStore.defaultCalendarForNewEvents;

            EKAlarm *objAlarm = [EKAlarm alarmWithAbsoluteDate:self.dateToBeSet];
            [calEvent addAlarm:objAlarm];

            NSError *error;
            BOOL _bStatus = [objStore saveEvent:calEvent span:EKSpanThisEvent commit:YES error:&error];

            UIAlertView *alertV;

            if(_bStatus)
            {
                alertV = [[UIAlertView alloc]initWithTitle:@"Congratulations" message:@"Saved To Calendar" delegate:nil cancelButtonTitle:@"Right On!" otherButtonTitles:nil];
                [alertV show];
            }
            else
            {
                alertV = [[UIAlertView alloc]initWithTitle:@"Alert" message:[NSString stringWithFormat:@"Error saving to calendar, with error %@.",[error localizedDescription]] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
                [alertV show];
            }
        }
            else
        {
            // code here for when the user does NOT allow your app to access the calendar
            UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Please grant access to the calendar, and try again later." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alertV show];
        }
        });
    }];

}


person Hitesh    schedule 19.05.2014    source источник
comment
Вы проверили параметр error (первый). В какой строке не идет?   -  person Larme    schedule 19.05.2014
comment
да. Это происходит внутри метода requestAccess. И, следовательно, отображает ошибку в предупреждающем сообщении. логическая переменная _bStatus оказывается ложной.   -  person Hitesh    schedule 19.05.2014
comment
EKSpanThisEvent сообщает календарю, что любые изменения, внесенные в событие, будут отражаться только на текущем событии. А не к будущим событиям, если они повторяются.   -  person Hitesh    schedule 20.05.2014


Ответы (2)



Удивительно, я тестирую свой код на двух разных устройствах, на одном он работает нормально, а на другом нет. Только что заглянул в настройки, и у того, с которым он не работает, календарь iCloud и напоминания отключены, просто включите их, и теперь все работает ... это должно быть ошибка

person Faithjda    schedule 06.04.2017