我添加了请求,如果用户选择允许访问,一切都会顺利运行,但如果用户拒绝或先前拒绝访问,则会出现问题.我添加了一个UIAlertVIEw来通知用户访问是否被拒绝,但UIAlertVIEw一直需要20-30秒才会出现,并在此期间完全禁用UI.调试显示[alertVIEw show]在延迟之前运行,即使它在延迟之后实际上没有显示.
为什么会出现这种延迟?如何将其删除?
[eventStore requestAccesstoEntityType:EKEntityTypeEvent completion:^(BOol granted,NSError *error) { if (granted) { [self createCalendarEvent]; } else { UIAlertVIEw *alertVIEw = [[UIAlertVIEw alloc] initWithTitle:@"Calendar Access DenIEd" message:@"Please enable access in Privacy Settings to use this feature." delegate:nil cancelbuttonTitle:@"OK" otherbuttonTitles:nil]; [alertVIEw show]; } }];解决方法 [alertVIEw show]不是线程安全的,因此它将UI更改添加到从中调度完成块而不是主队列的队列.我通过添加dispatch_async(dispatch_get_main_queue(),^ {})解决了这个问题;围绕完成块内的代码:
[eventStore requestAccesstoEntityType:EKEntityTypeEvent completion:^(BOol granted,NSError *error) { dispatch_async(dispatch_get_main_queue(),^{ if (granted) { [self createCalendarEvent]; } else { UIAlertVIEw *alertVIEw = [[UIAlertVIEw alloc] initWithTitle:@"Calendar Access DenIEd" message:@"Please enable access in Privacy Settings to use this feature." delegate:nil cancelbuttonTitle:@"OK" otherbuttonTitles:nil]; [alertVIEw show]; } }); }];总结
以上是内存溢出为你收集整理的ios – UIAlertView在完成块中调用时需要很长时间才能显示全部内容,希望文章能够帮你解决ios – UIAlertView在完成块中调用时需要很长时间才能显示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)