OpenUrl冻结应用程序超过10秒 [英] OpenUrl freezes app for over 10 seconds
问题描述
我目前正在开发一款需要打开浏览器才能显示网页的应用。
要做到这一点,我使用 [UIApplication sharedApplication] openURL
方法和一个网址。
I'm currently developing an App, that needs to open a browser to display a webpage.
To do that i use the [UIApplication sharedApplication] openURL
method with an url.
在iOS中6这很好用,但在iOS 7中冻结应用程序10秒以上,然后打开浏览器,一切都很好。
In iOS 6 this works perfectly, but in iOS 7 it freezes the app for 10+ seconds, then opens the browser and all is good.
使用临时配置会发生这种情况。互联网上的某个人评论说这是一个已知的问题,然而,我可以找到关于这个问题的一条评论。
This happens using ad hoc provisioning. Someone on the internet commented that this was a known problem, however, that one comment was all i could find regarding this problem.
推荐答案
我从Application Delegate didReceiveRemoteNotification:或didFinishLaunchingWithOptions调用 - [UIApplication openUrl:]时发现了同样的问题:自iOS 7以来。
I noticed the same problem when calling -[UIApplication openUrl:] from the Application Delegate didReceiveRemoteNotification: or didFinishLaunchingWithOptions: since iOS 7.
我通过延迟调用来解决它bit使用GCD:
I solved it by delaying the call a bit using GCD :
// objc
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] openURL:url];
});
它让iOS有一段时间完成应用程序初始化,然后执行调用没有任何问题。不要问我为什么。
It let iOS some time to finish application initialization and the call is then performed without any problem. Don't ask me why.
这对你有用吗?
由于这个答案经常出现,我添加了swift版本:
As this answer is often seen, I added the swift version:
// swift
dispatch_async(dispatch_get_main_queue()) {
UIApplication.sharedApplication().openURL(url)
}
这篇关于OpenUrl冻结应用程序超过10秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!