1
votes

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 open 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

2
You're not expecting Apple to approve this, are you?ceejayoz
I have no problem with this in the simulator (iOS 4.2 GM).Evan Mulawski
@ceejayoz: Apple will definitely not approve this behavior, but this may just be practice or for personal/in-house use.Evan Mulawski
I have to make it since the boss said so. I was also wondering why not just go to safari and type the link, but I don't have a choice. What I am doing here is just saving our clients a few seconds to type in the address...Ray
@Evan Mulawski: It doesn't work on either 4.0 or 4.1 iphone simulators, but it works on ipad 3.2Ray

2 Answers

4
votes

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:].

2
votes

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