HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UIAlertView在完成块中调用时需要很长时间才能显示大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序的一部分需要日历访问,这需要调用EKEventStore方法 – (void)requestAccessToEntityType:(EKEntityTypE)entityType完成:(EKEventStorerequestAccessCompletionHandler)从iOS 7开始完成.

添加了请求,如果用户选择允许访问,一切都会顺利运行,但如果用户拒绝或先前拒绝访问,则会出现问题.我添加一个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在完成块中调用时需要很长时间才能显示所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。