Upplication openURL background

In my iOS 4 app, I need to open the URL from the background at the time specified by the user. However, for some reason, I cannot run the url from the background for some reason. Here is my code to open the url:

if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]]) { // the URL wasn't opened. we will ignore this for now. } 

This code is run from the daemon stream created earlier. I tested this code on a simulator and the URL does not open, and for some reason the method returns YES , but when I open the application again (via quick application switching), it opens the URL. Is there a way I can get my application back to the forefront (not through local notification) so that the URL can open, or is it a bug or an undocumented function. Also, if there is another way to open a URL that will run in the background, this will also be useful.

+7
objective-c iphone background openurl fast-app-switching
source share
3 answers

I believe that I found it (it does not work on the simulator, because it passes commands to the terminal on the mac, since there is no command line for the simulator). Use this:

 system([[NSString stringWithFormat:@"uiopen \"%@\"", myUrlToOpen] UTF8String]); 

This will uiopen command (found via jailbreak) to the device, forcing it to open this URL. Hope this helps others in my position.

+5
source share

UIKit calls can only be made in the main thread. I think that since this works in the background thread, Safari is still visiting the url, but your application is still active. Try opening Safari right away and see if the URL is loaded.

The solution is to put this in the main thread and thus leave your application at runtime. This is not like what you want to do, sorry. If you want to visit the URL from your application, you can submit a UIWebView.

+4
source share

This is not supported by iOS. Per the relevant section of the Apple iOS Programming Guide :

Support for some types of background execution must be declared in advance by an application that uses them [through] an array containing one or more lines with the following values:

  • audio - the application plays audio content for the user while in the background.
  • location - the application informs users about its location, even while working in the background.
  • voip - the application provides the user the ability to make phone calls using an Internet connection.

...

In addition to the previous keys, iOS provides two other ways to work in the background:

  • Applications may request additional time from the system to complete a given task.
  • Applications can schedule delivery of local notifications at a predefined time.

Your use does not meet any of the allowed multitasking types.

+3
source share

All Articles