为什么 EKEventStore 在保存事件时会无限期挂起?
我正在尝试使用这段常见的代码创建一个事件并将其存储在默认日历中:
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
处,调用挂起。
I am trying to create an event and store it in the default calendar using this common piece of code:
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;
}
It gives not a single problem in the simulator, but when running it on the physical device this will hang on indefinitely when I call [eventDB saveEvent:span:error:]
. I tested in the simulator with iOS 4.2/4.3 and iOS 5.0.1, and on the real device I have iOS 5.0.1 installed.
What am I doing wrong here? Is it my fault or did I misconfigured the app somewhere?
Thank you.
Update
Here is the stack trace of the call when I pause the app via 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
At step #17
there is the call that hangs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是由 iOS 5 中的一个错误引起的,当为一个事件设置多个闹钟时,应用程序会崩溃。使用单个警报时一切正常。
我没有在 iOS 6 上尝试过这个,所以我无法告诉你 Apple 是否解决了这个问题。
This appears to be caused by a bug in iOS 5, and the app crashes when setting more than one alarm on an event. Everything works fine when using a single alarm.
I did not try this on iOS 6, so I cannot tell you if Apple solved the problem.