TwitterCounter for @bigclick_dean

dBlog.com.au

My Development Blog

Well while I have been working on the Blog Tutorial I have been learning alot about the iPhone SDK, and once you get into it you will find that it is really quite easy to use. Even the strict data typing!

This tutorial will take you through the process of building your own web browser (well a quick one anyway, with a hard coded URL or hard coded HTML content). When I get a spare minute I will come back and show you how to use the toolbar at the top to add searching, links, etc.

1. Setup Your Project

I am not going to go into the detail of setting up XCode or anything like that in this tutorial as I did it in the RSS Reader Part 1 tutorial, if you don’t know how to set it up then I suggest heading over here and checking it out.

In the top menu click File > New Project and then under the iPhone OS area you will need to choose Window-Based Application.

Window-Based Application Template

Name your project WebBrowserTutorial and click “Save”

2. Adding the UIWebView to the window

In the left hand pane under the Resources folder double click the “MainWindow.xib” . You should see the interface builder fire up and it should look something like below, if you don’t see the inspector window (the third window in the screenshot below) then in the top menu click Tools > Inspector.

Interface Builder Default Screen

Now simply draw the “Web View” component from the library on the right to the window (the second box) and it should automatically resize itself to fit the screen.

Now that the view is on the screen you ned to make some connections, first you will need to hold the control key and click+drag from the Web View to the “File’s Owner” Object in the first screen. You should see the following popup:

iPhone WebView delegate Popup

Just click on the “delegate” Outlet and you are set!

Save and Close the Interface Builder.

3. The Code Behind the Beast (given it is a really small and simple beast)

First off we are going to setup our header file for the UIWebView Outlet.

Open up the “WebBrowserTutorialAppDelegate.h” file from under the Classes folder in the left hand pane, it should look like this

//
//  WebBrowserTutorialAppDelegate.h
//  WebBrowserTutorial
//
//  Created by Dean on 16/09/08.
//  Copyright __MyCompanyName__ 2008. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface WebBrowserTutorialAppDelegate : NSObject  {
UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

We are going to add a UIWebView Outlet just below the “UIWindow *window” line.

The code you need to add is

IBOutlet UIWebView *webView;

What this does is it sets an UIWebView Outlet up and names it “webView” for us to use in the main controller.

Save this file and open up the “WebBrowserTutorialAppDelegate.m” file from the same classes folder.

The initial content should look something like this

//
//  WebBrowserTutorialAppDelegate.m
//  WebBrowserTutorial
//
//  Created by Dean on 16/09/08.
//  Copyright __MyCompanyName__ 2008. All rights reserved.
//

#import "WebBrowserTutorialAppDelegate.h"

@implementation WebBrowserTutorialAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}

- (void)dealloc {
[window release];
[super dealloc];
}

@end

We are going to add some code into the applicationDidFinishLaunching method that will be executed, you guessed it, after the application finishes lunching. Don’t you just love Apple’s function names?

Add the following code just below the “applicationDidFinishLaunching” line

// Example 1, loading the content from a URLNSURL
NSURL *url = [NSURL URLWithString:@"http://dblog.com.au"];

NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

// Example 2, loading the content from a string
//NSString *HTMLData = @"<h1>Hello this is a test</h1>";
//[webView loadHTMLString:HTMLData baseURL:nil];

Most of the code above is pretty easy to understand, I have included two options for you to play with. The first one will load the content from a url (in this case it is http://dblog.com.au) and in the second example it is loading the content from a string, this string can come from anywhere, you could dynamically generate it, it could come from an XML string (like a RSS Feed ;-) ) or pretty much anywhere!

To get the second example to work you will need to comment out the first three lines and uncomment the second two.

You should be ready to save your code and fire your application up.

4. I didn’t see anything! You Suck!

Never fear, I did that on purpose. As you may notice I am trying to press the issue of linking the Outlet to the actual component as if you dont start doing that from the start you will soon get lost and your application development will drive you batty!

You will need to open up the “MainWindow.xib” file in the resources folder again and Control click+drag from the “Web Browser Tutorial App Delegate” Object (see the first image below) to the Webview component in your window. You should see the second window below appear, when it does select the “webView” Outlet.

Web Browser Tutorial App Delegate ObjectUIWebView Outlet

Save and Close the Interface Builder again and try to run your program again, if you used the first example you would see the screen below

dBlog.com.au on your own iPhone Web Browser
[ad]

5. Conclusion

Well that’s it for this tutorial, have a go at playing around with the layout and the different UIWebView loader options and let me know how you go. I will be writing some more articles on the UIWebView in the near future, and hopefully they will help some people get their head around the iPhone Development SDK.

6. Extra Features (added 27/09/2008)

After some requests I have added some extra tips below.
First one is to load a file from the application bundle.
Open up the “WebBrowserTutorialAppDelegate.m” file and edit the applicationDidFinishLaunching function to look like below:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
	NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"html"];
	NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
	[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]]; 

    [window makeKeyAndVisible];
}

What this does is it load the UIWebView content from a local file (in our case “sample.html”).

Now make a new blank file i the resources file called “sample.html” and put the following contents in it:

<html>
<head>
<title>Sample</title>
</head>
<body>
<!-- Load Image from base64 string -->
Image Loaded from base64 string:<br/>
<img src="data:image/jpeg;base64,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" alt="2954488.jpg" /><br/>
<!-- Load Image from URL -->
Image Loaded from URL:<br/>
<img src="http://www.google.com.au/intl/en_au/images/logo.gif"/><br/>
This is the <strong>body</stron> of the text.<br/>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</body>
</html>

This is just a simple html file, but you can also embed images into the html by using their base64 value, check out http://www.abluestar.com/utilities/encode_base64/index.php for info on how to convert images into base64. By using base64 encoded strings you can build a totally self contained file with all images embedded into it.

7. Download the Project Files

I have finally added the source files for this tutorial, download it now!

Popularity: 31% [?]

Comments

There are 46 comments for this post.

  1. Ian lim on September 23, 2008 10:33 am

    Haha… Quick easy, again thanks for your post. Its help.
    Thanks. Hope to see your next posts.

    Regards,
    Ian Lim

  2. Daniel on September 25, 2008 10:56 pm

    Thanks – great on-the-spot tutorial :)

    One question though – can you link to a webpage (ex. html) that is saved in the project, ie. not browsed to via internet but located locally.

    I tried:

    NSURL *url = [NSURL URLWithString:@"iphonedev.html"];

    …and added the “iphonedev.html”-file in the “Other Sources”-folder (even tried “Resources”-folder) of the project, but it did not load that page.

    Do you have an idea?
    Thanks in advance, Daniel

  3. Dean on September 27, 2008 1:08 am

    Hey Daniel,

    You can load the contents from file and I have added the details onto the end of the tutorial. It will show you how to load the contents from a file and also how to embed images into the html.

    I hope that this helps you.

    -Dean

  4. Daniel on September 27, 2008 11:43 am

    Thanks again Dean :)

    I wasnt even aware that you could do that to images -pretty cool!

    However, the project I have in mind utilizes a huge amount of images and sounds, which will be very tedious to convert. And Im not sure that you can convert sound as well.

    So Im leaning towards just importing the whole html-structure that I have into resources-folder, including the images and sounds.

    But when I tried a simple example of just adding an image to the webpage, using:

    ..it did not show up even thought I imported it into the resource-folder where the html-file is located. So apparently there is another url-issue Im not aware of, or this is not possible?

    - Daniel

  5. dp on September 28, 2008 3:37 am

    Can you make these projects available for download?

    I’m not sure which step I’m missing:
    error: ‘url’ undeclared (first use in this function)

    Thanks!

  6. eok on September 28, 2008 10:21 pm

    i would like to have a browser on my iphone which sends with every klick or reload my gps-position to the webserver…
    like http://foo.bar/index.html$N=12.345&E=87.654
    or in a “special” variable like
    or anything else which might help…

    would it be very complicated to embed the core-location to the “own web browser” ??

    …eok

  7. Dart on September 29, 2008 11:29 am

    Hi,

    Sometimes, the Web content can take really long time to load on the phone. To keep the user engaged even then, I want to show a “Loader” image till the time HTML gets loaded. Can you suggest me a way to do it ?

    Thanks !

  8. Dean on September 30, 2008 12:11 am

    Hey All,

    I have just added a project download to the bottom of the tutorial with the source files and I have also fixed up a few errors in the tutorial, it should be clearer now!

    @Daniel: I have spent some time working out how to do what you are asking about and I have finally figured it out! I have made a new post for about it as it looks like it has been asked a fair few times. Hope that it is what you wanted!

    @dp: I have released the files for this project and that *url error was my bad, I have updated the tutorial, thanks for spotting that.

    @eok: That is beyond the scope of this tutorial but I cannot see why it wouldn’t be possible. You would need to load in the navigation framework and get the current location into a variable and then parse the HTML content searching for any <a> tags and append or replace the links on the page with the location variables. When I get some spare time I will have a go and post back my results.

    @Dart: That is true the content can take quite a while to load, I would suggest adding a UISearchBar or UINavigationBar to the view and then putting a UIActivityIndicator to the bar. You can extend the UIWebViewDelegate and implement the webViewDidStartLoad and webViewDidFinishLoad functions to know when the page has started and finished loading.

    Good Luck to all and I hope that my tutorials are helping everyone!

    -Dean

  9. dp on October 1, 2008 7:00 am

    Dean,

    Thanks for the fix as well as the project files. All of your work has been very helpful and appreciated.

    Is there a possibility of adding a modification to utilize rotation of the device for sideways viewing?

    Thanks again!

  10. finalcut on October 1, 2008 12:31 pm

    hi,
    is it possible to have a html button or link or just javascript call a method from the app?meaning having the html within the UIWebView interact with the application?
    Thanks

  11. Dean on October 2, 2008 1:00 am

    Howdy Everyone,

    I have just posted a new article on how to catch link clicks in a UIWebView this should help eok with appending the GPS Co-Ords onto the end of every request.

    Hope this helps you also finalcut!

    -Dean

  12. alex on October 5, 2008 9:15 pm

    Hey man this is great however my Mac is not working currently. Could you help me by possibly compiling it for me, since I can’t seem to get it to compile on the iPhone..

    All I need to do is hardcode a URL into it for an application I’m making!

    Thanks!

  13. Dean on October 8, 2008 9:32 pm

    Hey Alex,
    There would be no way for me to compile it for your iPhone as the actual hardware requires a signing certificate and application id specific to your phone.

    Sorry :-(

  14. gh3 on October 9, 2008 5:04 pm

    Hi Dean great work!

    May I ask you a couple of things about your source?

    I’m playing a bit with it with iPhone emulator, i’ve created a simple html file that use these two features:

    - sms:
    - tel:

    but calling for them in the webview seems not to work with the emulator.

    do you know if is a problem linked to the emulator or is something missing inside the code?

    thanks in advance :)

  15. AwayBBL on October 19, 2008 3:19 pm

    Dean,

    I’ve tried over and over to solve this one nagging problem…

    I have a Default.png that shows when the application starts up, then the screen goes blank, and then the web app loads.

    Is there a way to eliminate that “blank time”? What I’d like to have happen is that when the webapp is ready, there would be no blank screen.

    I saw in one of your replies to use webViewDidStartLoad and webViewDidFinishLoad functions, but I can’t seem to get it to eliminate the blank time.

  16. Steve on October 22, 2008 6:48 pm

    Hi Dean!
    First of all, let me thank you. Your tutorial it’s really well done and it helped me a lot.

    Now a question…

    From the sample.html, i tried to make a link to another html file (sample2.html) that i created in the main directory.
    In order to do that, i created another html code line under the one of “item3″:

    item4

    but it doesn’t seem to work.

    Can you help me with this problem?

    Thanks again!!!

    Steve

  17. Steve on October 22, 2008 6:50 pm

    sorry for the double post:
    the html code line i tried is:

    //item4//

  18. wintervssummer on November 29, 2008 6:22 pm

    I very much love summer :)
    Someone very much loves winter :(
    I Wish to know whom more :)
    For what you love winter?
    For what you love summer? Let’s argue :)

  19. Simon on January 16, 2009 7:38 am

    @Steve:

    I had the same problem, a friend solved it for me (I’m a complete noob at this) by changing the baseURL parameter thus:

    [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]] ];

  20. Glenn White on January 27, 2009 4:12 am

    These code samples have been very helpful. Now I can move on to the next problem, how launching the iPhone Maps app with a local KML overlay file.

    You should consider getting a PayPal “donate” button added to this site, if you haven’t (I don’t see one). For many of us, the iPhone and information technology are means to an end. We have enough trouble trying to get people and funding to do positive things. Blogs like this help us to focus on our work, and to spend less time learning new languages and platforms. For this I should be able to contribute a few bucks.

    Peace

    Glenn
    Washington.DC

  21. Amit Kshetarpal on January 27, 2009 2:29 pm

    Thanks for posting the tutorial and source code. I am using a web application to display several html files that are stored locally in the resource folder. I can only get the first file(sample) to open but none of the linked files to the first file open. Am I missing something? Is there a way to allow other files to open?
    Thanks,
    Amit

  22. ven on February 8, 2009 5:06 pm

    Hi,
    This was a nice tutorial,i got the results on my MAC
    (i am new to MAC & iphone development…so this is a big achivement for me)

    Just one question though, how do I take this on my iphone??

    I think this calls for a deployment blog post for the iphone.

    Thanks

  23. itsfall on February 12, 2009 6:43 am

    hello,
    how can i compile this to an .app file and put it on my iphone?

    when i choose device 2.2 and then build and run it gets an error.

    please help!!
    greetz
    itsfall

  24. Erik on March 4, 2009 9:42 am

    hi there,
    i am an beginner in making iphone apps, but i want to make it landscape mode. i have read some tutorials but you do not use an ViewController here so i do not know how to do that. Can someone help me?
    i have just followed the tutorial!,
    gr. Erik

  25. Danny on April 6, 2009 8:22 pm

    Hey Dean,
    I know this makes me seem really stupid, but I am having a bit of trouble in building the app at the very beginning.
    In step two, I do not have the “Library” window to drag the “Web View” component. Is there any way I can make that window appear?

  26. Danny on April 6, 2009 8:44 pm

    Hey Dean,
    nevermind my first comment, i got library to pop up, but what do you mean by
    ” draw the “Web View” component from the library on the right to the window (the second box) and it should automatically resize itself to fit the screen.”
    i am only able to double click the view controller component and pop up another box the same size as window

  27. lionkingden on May 11, 2009 5:32 pm

    Ok…
    I’m complete newbi to ojective c programming and say to the world of Mac :)
    I am trying to capture the location of the person on this browser app.

    now i wanted to modify the code so that the html part (example 2 above) of the webpage can have the location in some kind of form that i will use, for now i want to just display the location.

    I know this will not keep updating the location ..i just want to capture the current location when the app is launched thats it

    the problem is my code is hanging up in the do while loop and i am not able to figure out why
    here is the code for the mymaptrackerAppDelegate.m

    ****************************************

    #import “mymaptrackerAppDelegate.h”

    @implementation mymaptrackerAppDelegate

    @synthesize window;

    - (void)applicationDidFinishLaunching:(UIApplication *)application {

    // initialization of CLLocationManager

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];

    locationManager.delegate = self;
    locationManager.distanceFilter = 1000; // 1 kilometer
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    [locationManager startUpdatingLocation];

    //use the timestamp to get the latest location

    NSDate* eventDate = locationManager.location.timestamp;
    NSTimeInterval howRecent;
    do{

    howRecent = [eventDate timeIntervalSinceNow];
    }
    while(abs(howRecent) < 5.0);

    //stop gps after getting the recent location

    [locationManager stopUpdatingLocation];

    float lat= locationManager.location.coordinate.latitude+0.0;
    float lon= locationManager.location.coordinate.latitude+0.0;

    //create the HTML for the webpage

    NSString *HTMLData = [NSString stringWithFormat: @"latitude %f longitude %f at %c",lat, lon, howRecent];

    [webView loadHTMLString:HTMLData baseURL:nil];

    // Override point for customization after application launch
    [window makeKeyAndVisible];
    }

    - (void)dealloc {

    [window release];
    [super dealloc];
    }

    @end

  28. lionkingden on May 12, 2009 8:46 am

    ok that was dumb of me..just changing the fixed the hanging up problem. but my browser is showing 0.0000 for the latitude and longitude
    any idea why?

  29. anon on May 16, 2009 9:44 pm

    How would I send links that are for youtube and maps to the native apps instead of the full html page in the uiwebview browser?

  30. lionkingden on May 20, 2009 9:37 am

    here is the code that worked for me to get the GPS location in a browser enjoy
    ————–mymaptracker.h

    #import

    @interface mynaharmaptrackerAppDelegate : NSObject {
    UIWindow *window;

    CLLocationManager *locationManager;

    NSString *myhtmldata;

    IBOutlet UIWebView *webView;

    }
    @property (nonatomic, retain) IBOutlet UIWindow *window;

    @property (nonatomic, retain) CLLocationManager *locationManager;

    @property (nonatomic, retain) NSString *myhtmldata;

    @end

    ————————mymaptracker.m—-

    #import “mymaptrackerAppDelegate.h”

    @implementation mymaptrackerAppDelegate

    @synthesize window;
    @synthesize locationManager;
    @synthesize myhtmldata;

    - (void)applicationDidFinishLaunching:(UIApplication *)application {

    // initializing the location manager

    self.locationManager = [[CLLocationManager alloc] init];

    locationManager.delegate = self;
    // locationManager.distanceFilter = 1000; // 1 kilometer
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

    // Override point for customization after application launch
    [window makeKeyAndVisible];
    }

    - (void)dealloc {
    [locationManager release];
    [window release];
    [super dealloc];
    }

    - (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
    fromLocation:(CLLocation *)oldLocation{

    NSDate* eventDate = locationManager.location.timestamp;
    NSTimeInterval howRecent;

    // if the location as nt got in last 5 sec then keep trying to get the location
    do{

    howRecent = [eventDate timeIntervalSinceNow];

    }
    while(abs(howRecent) > 5.0);

    //get the latitude and longitude

    NSString *mylat= [[NSString alloc] initWithFormat:@”%g°”, newLocation.coordinate.latitude];

    NSString *mylon= [[NSString alloc] initWithFormat:@”%g°”, newLocation.coordinate.longitude];

    myhtmldata = [NSString stringWithFormat: @"/* Override style definitions as appropriate */body {width:480px;background:#ff0;margin:0;padding:0;font: large 'Trebuchet MS',Trebuchet,Arial,Verdana,sans-serif;;color:#333;}/* etc… */.not-iPhone {display:none;}Posting infolatitude=%@longitude=%@ how recent=%f",mylat, mylon, howRecent];
    [webView loadHTMLString:myhtmldata baseURL:nil];

    //stop the location manager

    [locationManager stopUpdatingLocation];

    }

    -(void)locationManager:(CLLocationManager *)manager
    didFailWithError:(NSError *)error {
    NSString *errorType = (error.code == kCLErrorDenied) ?
    @”Access Denied” : @”Unknown Error”;
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Error getting Location” message:errorType delegate:nil cancelButtonTitle:@”Okay” otherButtonTitles:nil];
    [alert show];
    [alert release];
    }
    @end

  31. michael on May 23, 2009 10:59 am

    whenever i try to build i get the error mssage” There is no SDK with that specific name…” can you help me plssss

  32. Christopher on July 3, 2009 5:12 pm

    I’m wondering how to add the pinch and zoom features to the browser. I was looking around google and I just put a UIScrollView over the WebView to get the pinch and zoom, then i used this code:
    [UIScrollView setZoomScale:1.0 animated:YES];

    and the program just doesn’t respond.

    The error:
    Warning: “UIScrollView” may not respond to “+setZoomScale:animated”

    Help please.

    Thanks.

  33. vijay on July 17, 2009 5:18 pm

    Thanks for the great tut.

    How to refer local files in href , Let us say , I want to link sample.html from my index.html

    index.html is not local

  34. Alan on July 19, 2009 4:10 pm

    Hi,

    Great tutorial thanks.

    One question I have if you use Webview to create a web browser how do you configure it to rotate when you rotate your iPhone?

    Thanks.

  35. Ben on August 8, 2009 9:57 am

    It doesn’t let me connect the Delegate to the Web View in step 4.
    It tries to select the view as a whole.

  36. Brandon on August 19, 2009 4:04 pm

    Hi,

    I was going through with this, and when it came to the part where you had to connect the app delegate to the web view, it wouldn’t let me. It would just let me connect to the window…

  37. Dan Sinclair on August 20, 2009 12:41 pm

    Hi,

    Great guide by the way, got my app up and running in minutes!

    Quick question though, is there anyway to use a php local file or does it have to be HTML? I’m fairly new to all the iPhone coding so please be patient!!

    Regards,

    Dan

  38. Noah on September 5, 2009 9:31 pm

    Is there any why to make a UIButton send you to a different website in the UIWebView without taking you out of the app? Any help would be greatly appreciated.

  39. Kevin on September 14, 2009 12:12 am

    Hi,

    Thanks for the tut… When I try to link the “Web Browser Tutorial App Delegate” Object to the Webview the window that pops up does not have webview, only window… Any help would be great thanks in advance.

    Kevin

  40. Satyam on September 18, 2009 2:31 am

    Its good article and tutorial. As mentioned by some one previously, I am showing the URL in webview. When some one clicks on the links inside the web page, I want the same to be opened in same web view. How can I do that? Or how can I show in a new browser window?

Trackbacks

  1. pligg.com
  2. How to Make an iPhone Application @ iBlog
  3. 100 Free Courses & Tutorials for Aspiring iPhone App Developers | Best Universities
  4. Apple iPhone development links | 72dpi.net.au
  5. 200ml » 100 Free courses for iPhone Dev
  6. 100 Free Courses & Tutorials for Aspiring iPhone App Developers | online classes college
  • There are no trackbacks for this post

Write a Comment