In App Web Browser for iPhone

This is the “BrowserApp” example. I am going to show you the simplest way to open the browser, from this app you can open any site. Suppose you want to open google.com just type the url and click the submit button.

Step 1: Open the Xcode and create a new Xcode project using View base application template. Give the application name “BrowserApp”. As shown in the figure below:

Step 2: Expand classes and notice Interface Builder created the BrowserAppViewController.h and BrowserAppViewController.m class for you. Expand Resources and notice the template generated a separate nib, BrowserAppViewController.xib.

Step 3: Open the BrowserAppViewController.h file and we have to add IBOutlet UITextField *textdata; To display the textfield, mention two IBAction. To perform the given action make the following changes in the file.

#import <UIKit/UIKit.h>

@interface BrowserAppViewController : UIViewController {
      IBOutlet UITextField *textdata;
      NSString *String;
}
@property (nonatomic retain) IBOutlet UITextField *textdata;
@property (nonatomic, copy) IBOutlet NSString *String;
(IBAction)SubmitB;
@end

Step 4: Double click the BrowserAppViewController.xib file and after that make the following changes.
A) Open the view window, first drag the Round Rect Button from the library and place it to the view window and select the button.

B) Open the view window, and drag the TextField from the library and place it to the view window.

Step 5: Open the BrowserAppViewController.m file and make the following changes in the file.

#import "BrowserAppViewController.h"
#import "BrowserAppAppDelegate.h"

@implementation BrowserAppViewController

@synthesize textdata;
@synthesize String;

(IBAction)SubmitB;    
{
        self.String = textdata.text;
        NSString *nameString = String;
       
        NSString* AUrl = [NSString stringWithFormat:@"%@", nameString];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:AUrl]];
       
}

Step 6: Now build and run the code and View the Output in the Simulator.

You can download source code from here BrowserApp

Leave a Reply

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