我在点击按钮时向日历添加事件.每当我点击该按钮时,Xcode会向我发出警告并将应用程序挂起大约几秒钟,然后将该事件添加到日历中.警告如下:
void _WebThreadLockFromAnyThread(bool),0x175bd5c0:从主线程或Web线程以外的线程获取Web锁.不应该从辅助线程调用UIKit.
我用于添加事件的代码如下:
- (IBAction)btn_reminder_click:(id)sender{
[self addEventTocalendar];
}
- (void)addEventTocalendar{
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted) { return; }
EKEvent *event = [EKEvent eventWithEventStore:store];
if (btn_appointment.isSelected) {
event.title = @"Appointment Reminder.";
}
else if (btn_pickup.isSelected){
event.title = @"Pickup Reminder";
}
event.startDate = self.selectedDate;
event.endDate = [event.startDate dateByAddingTimeInterval:60*60];//set 1 hour meeting
event.notes = txt_notes.text;
event.recurrenceRules = EKRecurrenceFrequencyDaily;
[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -5.0f]];
if (selectedIndex == 1) {
[event addRecurrenceRule:[[EKRecurrenceRule alloc]initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily interval:1 …Run Code Online (Sandbox Code Playgroud) ios ×1