UIApplication openURL background

烂漫一生 提交于 2019-11-27 23:12:29

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.

UIKit calls can only run on the main thread. I think that because this is running on a background thread, Safari still visits the URL, but your app is still active. Try opening Safari shortly after and see if it loaded the URL.

The solution would be to put this on the main thread, and thus leave your app at the time that code is run. That doesn't sound like what you want it to do, sorry. If you want to visit the URL from within your app you can present an UIWebView.

This isn't supported by iOS. Per the relevant section of Apple's iOS Programming Guide:

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

  • audio - The application plays audible content to the user while in the background.
  • location - The application keeps users informed of their location, even while running in the background.
  • voip - The application provides the ability for the user to make phone calls using an Internet connection.

...

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

  • Applications can ask the system for extra time to complete a given task.
  • Applications can schedule local notifications to be delivered at a predetermined time.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!