defaultCalendarForNewEvents failed

前端 未结 8 2311
北海茫月
北海茫月 2020-11-29 01:25

When I try to call [newEventStore defaultCalendarForNewEvents], it returns an error message says:

[707:907] defaultCalendarForNewEvents failed: Error Domain         


        
8条回答
  •  清歌不尽
    2020-11-29 02:16

    On iOS6, Apple introduced a new privacy control that allows the user to control the accessibility of contacts and calenders for each app. So, on the code side, you need to add some way to request the permission. In iOS5 or before, we can always call

    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 for iOS < 6.0
        [self performCalendarActivity:eventStore];
    }
    

提交回复
热议问题