开发者

iOS How to exit current app after using UIApplication openURL to launch a browser

开发者 https://www.devze.com 2023-01-25 20:50 出处:网络
I am very new to iOS development. The app I need is very simple: just open a web browser and go to a specific URL when my app is launched. So in the delegate file, in didFinishLaunchingWithOptions, I

I am very new to iOS development. The app I need is very simple: just open a web browser and go to a specific URL when my app is launched. So in the delegate file, in didFinishLaunchingWithOptions, I add a line of code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];

The app can o开发者_如何学Cpen safari and go to google, however when I press the home button and try to open the app again, I got a write screen. I know I must release the resource after I call the browser, but I don't know how to do it.

Thanks a lot.

Ray


As others have answered, your app likely won't be approved if this is all that your app is going to do, but to answer your question:

Your problem is that the app is multitasking on iOS 4, and -[UIApplicationDelegate didFinishLaunchingWithOptions:] doesn't get called again when the app comes back into focus from the background. (More on how the app delegate methods work with multitasking here.)

If this is all your app is going to do, then the easiest fix is to simply opt out of multitasking.

If you don't opt out, then you need to put that same 'openURL' logic in one of the app delegate methods that gets called when multitasking is used, for instance -[UIApplicationDelegate applicationDidBecomeActive:].


If your sole purpose is to launch a website, there's no need for an app (which Apple wouldn't approve anyways). By simply adding an apple-touch-icon.png image to your site's root, anyone can add the site to their home screen and have it look like an app.

http://www.apple.com/webapps/whatarewebapps.html

http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html

0

精彩评论

暂无评论...
验证码 换一张
取 消