1

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

Ray
  • 11
  • 1
  • 2
  • You're not expecting Apple to approve this, are you? – ceejayoz Nov 17 '10 at 22:40
  • I have no problem with this in the simulator (iOS 4.2 GM). – Evan Mulawski Nov 17 '10 at 22:40
  • @ceejayoz: Apple will definitely not approve this behavior, but this may just be practice or for personal/in-house use. – Evan Mulawski Nov 17 '10 at 22:41
  • 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 Nov 17 '10 at 22:44
  • @Evan Mulawski: It doesn't work on either 4.0 or 4.1 iphone simulators, but it works on ipad 3.2 – Ray Nov 17 '10 at 22:51
  • @Ray: Try using a method similar to Apple's LaunchMe sample code (using an Alert View before opening the URL): http://developer.apple.com/library/ios/#samplecode/LaunchMe/Listings/Classes_LaunchMeAppDelegate_m.html%23//apple_ref/doc/uid/DTS40007417-Classes_LaunchMeAppDelegate_m-DontLinkElementID_4 (Don't use `handleURl...`, just tell the user that you will be opening Safari) – Evan Mulawski Nov 17 '10 at 23:00
  • You should really, really convince your boss to not even try this. If Apple "don't need another fart app", they sure don't need a company bookmark app. Also, it surprises me that Sergey or Larry would even try this. ;) – Joseph Tura Nov 17 '10 at 23:09

2 Answers2

4

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

Jay Peyer
  • 2,019
  • 1
  • 19
  • 17
2

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

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • I don't think that is his sole purpose. His application may require registration before use, which is why I suggested in the comments to alert the user that they will be diverted to a web page. – Evan Mulawski Nov 17 '10 at 23:14