UIApplication openURL background

Richard J. Ross III picture Richard J. Ross III · Nov 13, 2010 · Viewed 7.9k times · Source

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.
}

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.

Answer

Richard J. Ross III picture Richard J. Ross III · Nov 13, 2010

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]);

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.