2015-09-18 42 views
0

我正在使用使用EKEventStore和EKCalendar的應用程序。EKCalendar在刪除應用程序後仍保留在日曆應用程序中

的EKEventStore是一個靜態的:

static EKEventStore *eventStore = nil; 

然後我用下面的方法來查看用戶是否允許我訪問他們的日曆。

- (void)requestAccess:(void (^)(BOOL granted, NSError *error))callback; 
{ 
    if (eventStore == nil) { 
     eventStore = [[EKEventStore alloc] init]; 
    } 
    // request permissions 
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:callback]; 

    //EKCalendar *calendar = nil; 
    NSString *calendarIdentifier = [[NSUserDefaults standardUserDefaults] valueForKey:calendarIdentifer]; 
    if (calendarIdentifier) { 
     self.calendar = [self retrieveCalendar]; 
    } 

} 

之後,我可以創建一個新的日曆並保存我的活動。但是,如果我刪除該應用程序,日曆仍保留在日曆應用程序中。當我運行應用程序時,我正在創建一個新的EKEventStore,這意味着我也在創建一個新的日曆。

這意味着,如果我刪除應用程序,並重新安裝多次我結束了一個巨大的同一日曆列表,只有最新的是在應用程序中訪問給我。刪除應用程序時是否可以刪除日曆?或者有什麼我可以做的來訪問創建的上一個日曆。

任何幫助非常讚賞。

回答

0

到現在爲止我沒有發現其他的解決方案,以便: 讓你以前的日曆,你可以按名稱這樣的搜索:

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

NSArray *calendarEvents = [eventDB calendarsForEntityType:EKEntityTypeEvent]; 
NSArray *calendarReminder = [eventDB calendarsForEntityType:EKEntityTypeReminder]; 

NSMutableArray *calendars = [NSMutableArray arrayWithArray:calendarEvents]; 
[calendars addObjectsFromArray:calendarReminder]; 

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; 
NSString *typeString = @""; 

for (EKCalendar *thisCalendar in calendars) 
    if([thisCalendar.title isEqualToString:@"YourcalendarName"]) 
     // your code 

,但用戶可以更改日曆名稱,這是有風險的,所以你可以得到它購買您創建日曆時可以存儲的ID,但是如果您與iCloud合併,則可以使用此ID:

與日曆完全同步將失去此標識符。您應該制定計劃來處理標識符不再可通過緩存其他屬性獲取的日曆。

相關問題