如果iCloud设置为不同步提醒,则无法创建本地EKCalendar(提醒) [英] Unable to create local EKCalendar (Reminders) if iCloud is set to not sync Reminders
问题描述
在这里遇到一个非常奇怪的问题,在我看来这是EventKit API的问题,我只是想检查一下我没做什么。
Hitting a very strange issue here, which seems to me to be an issue with the EventKit API and I just want to check it's nothing I'm doing.
测试用例1:
- 在应用程序隐私中启用提醒
- 设备有iCloud帐户,但设置为不同步提醒
- 我可以在Apple的提醒应用中创建本地提醒列表
- ISSUE - 尝试使用EKSourceTypeLocal类型的源创建实体类型EKEntityTypeReminder的新日历失败
- Reminders are enabled in Privacy for the app
- The device has an iCloud account, but it's set to not sync reminders
- I can create a local reminders list in the 'Reminders' app from Apple
- ISSUE - Trying to create a new calendar of entity type EKEntityTypeReminder with a source of type EKSourceTypeLocal fails
测试用例2:
- 在应用程序隐私中启用提醒
- 设备没有iCloud帐户
- 我可以在Apple的提醒应用中创建本地提醒列表
- 我可以通过EK创建本地提醒列表API
- Reminders are enabled in Privacy for the app
- The device has no iCloud account
- I can create a local reminders list in the 'Reminders' app from Apple
- I can create a local reminders list via the EK API
测试案例3:
- Privac中启用了提醒y for the app
- 设备有iCloud帐户并设置为同步提醒
- 我可以创建 iCloud 来自Apple的提醒应用程序中的提醒列表
- 我可以通过EK API创建iCloud提醒列表
- Reminders are enabled in Privacy for the app
- The device has an iCloud account and is set to sync reminders
- I can create an iCloud reminders list in the 'Reminders' app from Apple
- I can create an iCloud reminders list via the EK API
我是疯了还是这是API的错误?
Am I going crazy or is this a bug with the API?
干杯!
这是代码:
EKCalendar *remindersList = nil;
NSString *remindersListIdent = [[NSUserDefaults standardUserDefaults] objectForKey:kReminderListIdentDefaultsKey];
if(remindersListIdent) {
remindersList = [store calendarWithIdentifier:remindersListIdent];
if(remindersList) {
// has valid reminders list so save reminder and return (don't run rest of function)
[self saveReminder:reminder toCalendar:remindersList withTypeLabel:reminderTypeLabel];
return;
}
}
NSArray *currentCalendars = [store calendarsForEntityType:EKEntityTypeReminder];
for(EKCalendar *cal in currentCalendars) {
if([[cal title] isEqualToString:@"My App Name"]) {
remindersList = cal;
[[NSUserDefaults standardUserDefaults] setObject:[remindersList calendarIdentifier] forKey:kReminderListIdentDefaultsKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[self saveReminder:reminder toCalendar:remindersList withTypeLabel:reminderTypeLabel];
return;
}
}
EKSource *localSource = nil;
for (EKSource *source in store.sources) {
if (source.sourceType == EKSourceTypeCalDAV && [source.title isEqualToString:@"iCloud"]) {
localSource = source;
break;
}
}
if(localSource) {
remindersList = [self newCalendarListInSource:localSource];
}
if(!remindersList) {
for (EKSource *source in store.sources) {
if (source.sourceType == EKSourceTypeLocal) {
localSource = source;
remindersList = [self newCalendarListInSource:localSource];
if(remindersList) {
break;
}
}
}
}
if(!remindersList) {
dispatch_async(dispatch_get_main_queue(), ^{
// show error message
});
}
else {
[[NSUserDefaults standardUserDefaults] setObject:[remindersList calendarIdentifier] forKey:kReminderListIdentDefaultsKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[self saveReminder:reminder toCalendar:remindersList withTypeLabel:reminderTypeLabel];
}
这是newCalendarListInSource的内容:
And this is the contents of newCalendarListInSource:
EKCalendar *remindersList;
remindersList = [EKCalendar calendarForEntityType:EKEntityTypeReminder eventStore:store];
remindersList.source = localSource;
[remindersList setTitle:@"My App Name"];
NSError *listCreateError = nil;
[store saveCalendar:remindersList commit:YES error:&listCreateError];
if(!listCreateError) {
return remindersList;
}
else {
NSLog(@"Failed to create reminders list with error: %@", [listCreateError localizedDescription]);
推荐答案
对于所有仍有问题的人,请检查你的您使用的 EKSourceType
(如果手机中存在)。对于Swift,请尝试使用 EKSourceType.Exchange
。请注意,我的Outlook / Exchange帐户已同步到我的手机。
For all still having a problem with this, check your EKSourceType
that you use if it exists in your phone. For Swift, try using the EKSourceType.Exchange
. Note that I have an Outlook/Exchange account synced to my phone.
我知道这很模糊,但当我使用 EKSourceType.Exchange
时,它对我有用。 (玩它)
I know that this is very vague, but when I used EKSourceType.Exchange
, it worked for me. (Play with it)
这篇关于如果iCloud设置为不同步提醒,则无法创建本地EKCalendar(提醒)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!