问题描述
在我的 iOS 4 应用程序中,我需要在用户指定的时间从后台打开一个 URL.但是,由于某种原因,我无法从后台启动 URL.这是我打开 URL 的代码:
In my iOS 4 application, I need to open a URL from the background, at a time specified from the user. However, for some reason, I cannot launch a URL from the background for some reason. Here is my code for opening a URL:
if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]])
{
// the URL wasn't opened. we will ignore this for now.
}
所有代码都是从之前创建的守护线程启动的.我已经在模拟器上测试了这段代码,并且没有打开 URL,并且由于某种原因该方法返回 YES
,但是当我再次打开我的应用程序(通过快速应用程序切换)时,它会打开网址.有什么方法可以让我的应用程序在此时再次进入前台(不是通过本地通知),以便可以打开 URL,或者这是一个错误或未记录的功能.另外,如果有其他方法可以在后台打开 URL,那也会很有帮助.
That code is all being launched from a daemon thread created earlier. I have tested this code on the simulator, and the URL is not opened, and the method returns YES
for some reason, but when I open my application again (via fast-app-switching) it opens the URL. Is there some way that I can make my application come to the foreground again at this point (not via a local notification) so that the URL may open, or is this a bug or undocumented feature. Also, if there is another way to open the URL, that will work in the background, that would be helpful too.
推荐答案
我相信我已经找到了(在模拟器上不起作用,因为它将命令传递到 mac 上的终端,因为没有命令行模拟器).使用这个:
I believe I have found it (doesn't work on simulator, because it passes commands to the terminal on the mac, as there is no command line for the simulator). Use this:
system([[NSString stringWithFormat:@"uiopen "%@"", myUrlToOpen] UTF8String]);
这会将命令 uiopen
(通过越狱找到)传递给设备,强制其打开该 URL.我希望这对处于我地位的其他人有所帮助.
That will pass the command uiopen
(found via jailbreak) to the device, forcing it to open that URL. I hope this helps others in my position.
这篇关于UIApplication openURL 背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!