OpenUrl 冻结应用程序超过 10 秒 [英] OpenUrl freezes app for over 10 seconds

查看:16
本文介绍了OpenUrl 冻结应用程序超过 10 秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个应用程序,需要打开浏览器才能显示网页.为此,我使用带有 url 的 [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.

推荐答案

从应用程序委托 didReceiveRemoteNotification: 或 didFinishLaunchingWithOptions: 调用 -[UIApplication openUrl:] 时,我发现了同样的问题.

I noticed the same problem when calling -[UIApplication openUrl:] from the Application Delegate didReceiveRemoteNotification: or didFinishLaunchingWithOptions: since iOS 7.

我通过使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆