gpt4 book ai didi

ios - 无法在默认的 iOS 7 日历中创建事件

转载 作者:可可西里 更新时间:2023-11-01 05:22:04 26 4
gpt4 key购买 nike

#import <EventKit/EventKit.h>

我无法在默认的 iOS 日历中创建事件。

EKEventStore *eventStore = [[EKEventStore alloc] init];
for (EKSource *source in eventStore.sources)
{
if (source.sourceType == EKSourceTypeCalDAV || source.sourceType == EKSourceTypeLocal)
{
NSLog(@"I found it");
break;
}
}

从这里开始它无法返回任何来源。当我构建和运行应用程序时,没有任何请求允许其访问默认日历。

总而言之,我得到一个空数组:

[eventStore.sources count]

即使我尝试在不创建新日历的情况下添加事件(使用

[eventStore defaultCalendarForNewEvents]

最佳答案

我猜访问 EKEventStore 时有问题,要检查权限请尝试以下操作,

 EKEventStore *eventStore = [[EKEventStore alloc] init];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]){
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
NSLog(@"GRANTED: %c", granted);
for (EKSource *source in eventStore.sources)
{
if (source.sourceType == EKSourceTypeCalDAV || source.sourceType == EKSourceTypeLocal)
{
NSLog(@"I found it");
break;
}
}
}];

}

希望对你有帮助

关于ios - 无法在默认的 iOS 7 日历中创建事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19177262/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com