此代码在iOS 11之前一直工作正常,但是现在在iOS 11中,ID工作正常,但标题返回null。
NSArray *availablePersonalCalendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *cal in availablePersonalCalendars) {
NSLog(@"ID: %@", cal.calendarIdentifier);
NSLog(@"Title: %@", cal.title)
}
如果您知道如何解决此问题,请帮助我。谢谢,
我已经使用了此代码,并且在iOS 11:
中正常工作EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted, NSError * _Nullable error) {
NSArray *availablePersonalCalendars = [store calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *cal in availablePersonalCalendars) {
NSLog(@"ID: %@", cal.calendarIdentifier);
NSLog(@"Title: %@", cal.title);
}
}];
还要确保在plist中包含 nscalendAsusAusavedEscription 键,并提供有关如何使用此信息的解释性文本。
https://developer.apple.com/library/content/documentation/general/reference/infoplistkeyreference/articles/cocoakeys.htmll#/apple/apple_ref/doc/doc/doc/uid/tp40009251-sw151-sw15
您应该存储参考对您的EKEventStore
对象。以某种方式与缺少日历的标题有关。不要忘记在查询日历之前请求权限。
Objective-C :
@interface Some ()
@property (nonatomic) EKEventStore *store;
@property (nonatomic) NSArray<EKCalendar *> *calendars;
@end
@implementation Some
- (void)prepare
{
self.store = [EKEventStore new];
self.calendars = @[];
}
- (void)loadCalendars
{
self.calendars = [self.store calendarsForEntityType:EKEntityTypeEvent];
}
@end
swift :
let store = EKEventStore()
var calendars: [EKCalendar] = []
func loadCalendars() {
calendars = store.calendars(for: .event)
}