How to load a URL in Objective C or Cocoa in iPhone?/ Open Safari in Objective C

By | March 1, 2011

This code snippet helps you to open a webpage in Safari.
Code uses openURL to load the webpage in the web browser.
Write this function as an action to a button………

- ( IBAction ) loadWebPageInSafari : ( id ) sender
{
          NSURL *my_URL = [NSURL URLWithString:[Your_URL stringValue]];
          if ( [ [NSWorkspace sharedWorkspace] openURL : my_URL ] ){
                   NSLog(@” URL Loaded................”);
         }else{
                   NSLog(@" Failed to Load URL.....");
         }
}

Leave a Reply

Your email address will not be published. Required fields are marked *