2012-07-24 71 views
0

我已成功創建日曆並通過編碼創建日曆,並在該日曆中創建活動。我可以通過編碼刪除日曆,但是當我選擇iPhone的日曆並刪除新創建的日曆時,此時刪除不起作用。請提出 。從iPhone中刪除日曆的問題

EKEventStore *eventStore = [[EKEventStore alloc] init]; 
EKCalendar *calendar = [EKCalendar calendarWithEventStore:eventStore]; 
calendar.title = CALENDAR_TITLE; 

// Iterate over all sources in the event store and look for the local source 
EKSource *theSource = nil; 
for (EKSource *source in eventStore.sources) { 
    if (source.sourceType == EKSourceTypeLocal) { 
     theSource = source; 
     break; 
    } 
} 

if (theSource) { 
    calendar.source = theSource; 
} else { 
    NSLog(@"Error: Local source not available"); 
    return; 
} 

NSError *error = nil; 
BOOL result = [eventStore saveCalendar:calendar commit:YES error:&error]; 
if (result) { 
    NSLog(@"Saved calendar to event store.") 
    self.calendarIdentifier = calendar.calendarIdentifier; 
} else { 
    NSLog(@"Error saving calendar: %@.", error); 
} 


// Delete Calendar 
EKEventStore *eventStore = [[EKEventStore alloc] init]; 
EKCalendar *calendar = [eventStore calendarWithIdentifier:self.calendarIdentifier]; 
if (calendar) { 
    NSError *error = nil; 
    BOOL result = [self.eventStore removeCalendar:calendar commit:YES error:&error]; 
    if (result) { 
     NSLog(@"Deleted calendar from event store."); 
    } else { 
     NSLog(@"Deleting calendar failed: %@.", error); 
    } 
} 

回答

0

我也經歷過同樣的情況。在iOS 5.0上,它實際上看起來像日曆也被用於自動提醒。 您需要從提醒應用程序中刪除日曆。

我認爲這可能是iOS中的一個錯誤,即使您未成功嘗試從日曆應用中刪除以編程方式創建的日曆,您甚至不會收到通知。