我正在尝试让用户有权编辑日历
我把日志显示为每个方法运行所花费的时间,它表示它只有几毫秒
问题是,在我请求许可后,ui线程似乎被阻止超过一分钟
日志说:
2014-11-09 22:09:07.236 FixGift[60052:22b] I,-[EACalendarManager getLocalEventCalendarsWithHandler:]:91
[fg16,179,176;before start request[;
2014-11-09 22:09:08.795 App[60052:4607] I,__55-[EACalendarManager getLocalEventCalendarsWithHandler:]_block_invoke:101
[fg16,179,176;before start callback[;
2014-11-09 22:09:08.805 App[60052:4607] I,__42-[EANewEventViewController askPermission:]_block_invoke:433
[fg16,179,176;before save event[;
2014-11-09 22:09:08.807 App[60052:4607] I,__69-[EANewEventViewController saveEventToCalendarWithManager:eventInfo:]_block_invoke:443
[fg16,179,176;created calendar[;
2014-11-09 22:09:08.840 App[60052:60b] I,-[EABaseViewController dealloc]:106
[fg16,179,176;deallocated:EABaseViewController[;
2014-11-09 22:09:08.841 App[60052:60b] I,-[EABaseViewController dealloc]:106
[fg16,179,176;deallocated:EABaseViewController[;
2014-11-09 22:09:08.840 App[60052:4607] I,__42-[EANewEventViewController askPermission:]_block_invoke:435
[fg16,179,176;after save event[;
2014-11-09 22:09:08.842 App[60052:4607] I,__55-[EACalendarManager getLocalEventCalendarsWithHandler:]_block_invoke:107
[fg16,179,176;after callback[;
-(void)getLocalEventCalendarsWithHandler:(EACalendarManagerEventsCallback)callback{
__weak typeof (self)weakself = self;
if(!self.eventsAccessGranted){
LogInfo(@"before start request");
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if(!granted){
NSLog(@"Error requesting access to events:%@",error);
if(callback){
callback(granted,error,nil);
}
return ;
}
LogInfo(@"before start callback");
NSArray *calendars =[weakself getLocalEventCalendars];
if(callback){
callback(granted,error,calendars);
}
LogInfo(@"after callback");
}];
}else {
NSArray *calendars =[self getLocalEventCalendars];
if(callback){
callback(YES,nil,calendars);
}
}
}
我该怎么做才能解决问题?
答案 0 :(得分:0)
您的完成处理程序将在后台线程上执行。应该在主队列上执行UI的所有更新。
您可以在回调块内的主队列上调度,也可以更安全地调用主队列上的回调。