1

我正在尝试向用户询问编辑日历的权限

我放了日志来显示每个方法运行所需的时间,它说它是几毫秒

问题是,在我请求权限后,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);
        }
    }
}

我能做些什么来解决这个问题?

4

1 回答 1

0

您的完成处理程序将在后台线程上执行。UI 的所有更新都应在主队列上执行。

您可以在回调块内的主队列上调度,或者在主队列上调用回调可能更安全。

于 2014-11-09T20:32:37.937 回答