3.12. Invoking Safari

Occasionally, it may be appropriate to call Safari to bring up a web page for your application; for example, when the user presses a Donate or Home Page button in your application's credits page. The UIApplication class supports an openURL method that can seamlessly launch Safari and load a web page in a new window.

To use this, your application needs to create an NSURL object. You were introduced to the NSURL earlier in this chapter. The NSURL object is passed to the application's openURL method, where the application framework processes and launches the appropriate handler application:

 

NSURL *url = [ [ NSURL alloc ] initWithString: @"http://www.oreilly.com/" ];
[ [ UIApplication sharedApplication ] openURL: url ];