为什么EKEventStore会在保存事件时无限期地挂起?

时间:2012-02-19 23:07:27

标签: ios cocoa-touch ekeventkit

我正在尝试使用这段常见代码创建一个事件并将其存储在默认日历中:

EKEventStore *eventDB = [[EKEventStore alloc] init];
EKEvent *myEvent    = [EKEvent eventWithEventStore:eventDB];
myEvent.title       = titolo;
myEvent.startDate   = [NSDate date];
myEvent.calendar = [eventDB defaultCalendarForNewEvents];
myEvent.endDate     = data;
myEvent.allDay      = NO;
myEvent.notes       = note;

NSMutableArray *myAlarmsArray = [[NSMutableArray alloc] init];

EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-300]; // 5 minutes
EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-3600]; // 1 hour
EKAlarm *alarm3 = [EKAlarm alarmWithRelativeOffset:-86400]; // 1 day

[myAlarmsArray addObject:alarm1];
[myAlarmsArray addObject:alarm2];
[myAlarmsArray addObject:alarm3];

myEvent.alarms = myAlarmsArray;
[myAlarmsArray release];

NSError *err;
[eventDB saveEvent:myEvent span:EKSpanThisEvent error:&err];
if (err == noErr) {
    return YES;
} else {
    [Utils logError:err];
    return NO;
}

它在模拟器中没有出现任何问题,但是当它在物理设备上运行时,当我调用[eventDB saveEvent:span:error:]时,这将无限期地挂起。我在iOS 4.2 / 4.3和iOS 5.0.1的模拟器中进行了测试,在真实设备上安装了iOS 5.0.1。

我在这里做错了什么?是我的错还是我在某个地方错误配置了应用程序?

谢谢。

更新

当我通过Xcode暂停应用程序时,这是调用的堆栈跟踪:

#0  0x3622a060 in semaphore_wait_trap ()
#1  0x36f55450 in _dispatch_thread_semaphore_wait$VARIANT$up ()
#2  0x36f536b4 in _dispatch_barrier_sync_f_slow ()
#3  0x36f53632 in dispatch_barrier_sync_f$VARIANT$up ()
#4  0x36f5328e in dispatch_sync_f$VARIANT$up ()
#5  0x36f53910 in dispatch_sync$VARIANT$up ()
#6  0x31b46628 in -[EKEventStore _deleteObject:] ()
#7  0x31b48f28 in -[EKPersistentObject primitiveRemoveRelatedObject:forKey:] ()
#8  0x31b43972 in -[EKPersistentEvent _adjustForNewCalendar] ()
#9  0x31b43490 in -[EKPersistentEvent validate:] ()
#10 0x31b708a2 in __23-[EKEventStore commit:]_block_invoke_0 ()
#11 0x36f537ea in _dispatch_barrier_sync_f_invoke ()
#12 0x36f5365a in dispatch_barrier_sync_f$VARIANT$up ()
#13 0x36f5328e in dispatch_sync_f$VARIANT$up ()
#14 0x36f53910 in dispatch_sync$VARIANT$up ()
#15 0x31b43200 in -[EKEventStore commit:] ()
#16 0x31b3f254 in -[EKEventStore saveEvent:span:commit:error:] ()
#17 0x31b3f11a in -[EKEventStore saveEvent:span:error:] ()
#18 0x00009018 in +[Utils creaEventoDaCalendario:note:data:] at /myPrivatePath/Utils.m:123
#19 0x0000c144 in -[PotenzialitaController(hidden) salvaEvento] ()
#20 0x34279434 in -[NSObject performSelector:withObject:withObject:] ()
#21 0x376e39ea in -[UIApplication sendAction:to:from:forEvent:] ()
#22 0x377a93ce in -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] ()
#23 0x34279434 in -[NSObject performSelector:withObject:withObject:] ()
#24 0x376e39ea in -[UIApplication sendAction:to:from:forEvent:] ()
#25 0x376e39a6 in -[UIApplication sendAction:toTarget:fromSender:forEvent:] ()
#26 0x376e3984 in -[UIControl sendAction:to:forEvent:] ()
#27 0x376e36f4 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#28 0x376e402c in -[UIControl touchesEnded:withEvent:] ()
#29 0x376e250e in -[UIWindow _sendTouchesForEvent:] ()
#30 0x376e1f00 in -[UIWindow sendEvent:] ()
#31 0x376c84ec in -[UIApplication sendEvent:] ()
#32 0x376c7d2c in _UIApplicationHandleEvent ()
#33 0x30afadf2 in PurpleEventCallback ()
#34 0x342f3552 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#35 0x342f34f4 in __CFRunLoopDoSource1 ()
#36 0x342f2342 in __CFRunLoopRun ()
#37 0x342754dc in CFRunLoopRunSpecific ()
#38 0x342753a4 in CFRunLoopRunInMode ()
#39 0x30af9fcc in GSEventRunModal ()
#40 0x376f6742 in UIApplicationMain ()
#41 0x00002cbc in main at /myPrivatePath/main.m:14

在步骤#17,有一个挂断的电话。

1 个答案:

答案 0 :(得分:0)

这似乎是由iOS 5中的错误引起的,当在事件上设置多个警报时应用程序崩溃。使用单个闹钟时一切正常。

我没有在iOS 6上试试这个,所以我不能告诉你Apple是否解决了这个问题。