2015-09-28 97 views
2
EKReminder *reminder = [EKReminder reminderWithEventStore:self.eventStore]; 
reminder.title  = @"E-Cold 1mg"; 
reminder.calendar = [_eventStore defaultCalendarForNewReminders]; 
NSDate *date   = [_myDatePicker date]; 

// get today date 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // here we create NSDateFormatter object for change the Format of date.. 
[dateFormatter setDateFormat:@"YYY-MM-dd"]; //Here we can set th 

NSLog(@"%@",[dateFormatter stringFromDate:date]); 
EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:date]; 

[reminder addAlarm:alarm]; 

// EKRecurrenceFrequency頻率;錯誤域= EKCADErrorDomain代碼= 1013 「該操作不能完成(EKCADErrorDomain錯誤1013)。」

NSError *error = nil; 

[_eventStore saveReminder:reminder commit:YES error:&error]; 

if (error) 
{ 
    NSLog(@"error = %@", error); 
}` 

上面的代碼設置爲鬧鈴是好的,但是當我重新模擬器調用此方法顯示了新的提醒了這個錯誤時產生錯誤的默認日曆:

Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)" 
error = Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0x7f8fca4eac80 {NSLocalizedDescription=No calendar has been set.} 

和再次停止並構建應用程序的工作fine.Why這個錯誤即將首次推出

回答

1
EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease]; 
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) { 
    // iOS 6 and later 
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
     if (granted) { 
      // code here for when the user allows your app to access the calendar 
      [self performCalendarActivity:eventStore]; 
     } else { 
      // code here for when the user does NOT allow your app to access the calendar 
     } 
    }]; 
} else { 
    // code here 
    [self performCalendarActivity:eventStore]; 
} 

,或者可以有如下問題 快速修復:

  1. 轉到設置
  2. 選擇隱私
  3. 選擇提醒
  4. 選擇你的應用程序,並允許「提醒」爲開的訪問。
相關問題