gpt4 book ai didi

ios - EKEvent 不保存 EKAlarm 但仅在某些设备上没有错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:00:08 24 4
gpt4 key购买 nike

我正在创建一个带有 EKAlarmEKEvent,如下面的代码所示。在大多数情况下,这非常有效。

但是,在有限数量的设备上,不会设置闹钟。事件已在日历中创建,但缺少警报。

EKEvent* event = [EKEvent eventWithEventStore:eventStore];

event.title = @"Event Title";
event.allDay = YES;
event.notes = @"Event Notes";
event.calendar = calendar ? calendar : eventStore.defaultCalendarForNewEvents;

event.startDate = date;
event.endDate = date;

EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:reminderDate];
[event addAlarm:alarm];

NSError* error = nil;

BOOL success = [eventStore saveEvent:event span:EKSpanThisEvent commit:TRUE error:&error];

此时,成功为 YES,错误为 nil。此外,事件对象有一个包含警报对象的警报数组。如果我尝试删除该警报并保存事件(应用程序崩溃,因为警报实际上并不存在),这将成为一个问题。

我无法确定受影响设备的独特之处。每次在以下设备上都会发生:

  • 装有 iOS 8.1.1 的 iPhone 6
  • 装有 iOS 8.4 的 iPhone 6
  • 装有 iOS 8.4 的 iPhone 5

而下面没有问题:

  • 装有 iOS 8.4 的 iPhone 6
  • 装有 iOS 8.3 的 iPhone 6
  • 装有 iOS 8.0.2 的 iPhone 6
  • iOS 8.1 和 iOS 8.4 的 iPhone 模拟器
  • 装有 iOS 9 的 iPhone 5

以上所有设备都是不同的物理设备。所以它似乎不是任何特定的设备型号或 iOS 版本。

我也尝试过不同的日历,包括本地日历和同步(例如 Exchange、Google)日历。在受影响的设备上,所有日历都会出现此问题。

我还尝试设置/不设置时区覆盖和默认警报时间(设置 > 邮件、联系人、日历)。

有人遇到过这个问题吗?


更新:

我已经构建了一个测试应用程序,以将问题与原始应用程序中可能发生的任何其他事情隔离开来。它在大多数设备上都能完美运行,但问题仍然存在于受影响的设备上。

这是在 [eventStore saveEvent:event span:EKSpanThisEvent commit:TRUE error:&error] 之后 EKEvent 对象的样子。请注意,此调用返回 YES 并且 error 为 nil。

EKEvent Object: EKEvent <0x1742e1e00>
{
EKEvent <0x1742e1e00>
{ title = Event Title;
location = ;
calendar = EKCalendar <0x1740ab4c0> {title = Calendar; type = Exchange; allowsModify = YES; color = #CC73E1;};
alarms = (
"EKAlarm <0x170085190> {triggerDate = 2015-09-02 23:21:53 +0000}"
);
URL = (null);
lastModified = 2015-08-25 23:21:53 +0000;
startTimeZone = (null);
startTimeZone = (null)
};

location = ;
structuredLocation = (null);
startDate = 2015-09-04 14:00:00 +0000;
endDate = 2015-09-05 13:59:59 +0000;
allDay = 1;
floating = 1;
recurrence = (null);
attendees = (null);
travelTime = (null);
startLocation = (null);
};

然后我调用 [eventStore reset],它看起来像这样:

EKEvent Object: EKEvent <0x1702e2600>
{
EKEvent <0x1702e2600>
{ title = Event Title;
location = ;
calendar = EKCalendar <0x1740ad200> {title = Calendar; type = Exchange; allowsModify = YES; color = #CC73E1;};
alarms = (null);
URL = (null);
lastModified = 2015-08-25 23:21:53 +0000;
startTimeZone = (null);
startTimeZone = (null)
};
location = ;
structuredLocation = (null);
startDate = 2015-09-04 14:00:00 +0000;
endDate = 2015-09-05 13:59:59 +0000;
allDay = 1;
floating = 1;
recurrence = (null);
attendees = (null);
travelTime = (null);
startLocation = (null);
};

更新 #2

我已经进行了更多测试,并且能够在 Exchange 同步日历上一致地重现该问题。我之前已经排除了这种可能性,因为我曾要求客户尝试选择非 Exchange 日历,但他们报告说问题仍然存在。

最佳答案

据我所知,这似乎是一个 iOS 错误。我能够确定,如果我在保存 EKEvent 之后添加一个 EKAlarm 然后再次保存它,警报将成功添加并显示为附加到日历应用程序中的事件。

因此,我能够通过在保存后重置 EKEventStore、重新加载 EKEvent 来解决此问题,如果 EKAlarm 丢失,添加并再次保存。

if (!error) {
[eventStore reset];

event = [eventStore eventWithIdentifier:event.eventIdentifier];

if (event.alarms.count < 1) {
EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:reminderDate];
[event addAlarm:alarm];

[eventStore saveEvent:event span:EKSpanThisEvent commit:TRUE error:&error];
}
}

关于ios - EKEvent 不保存 EKAlarm 但仅在某些设备上没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32132104/

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