Creating a Native iPhone Application with iWeb Kit in Objective C

Use the instructions in Chapter 2 to create a new native UlWebView-based application.

To include iWebKit in an application, you need to place a copy of the iWebKit framework in your iPhone project directory. In this example, you will build an app using the iWebKit feature demo.

In the root directory of the iWebKit Framework you downloaded earlier, find the folder entitled Demo. Drag the contents of the Demo folder into the Resource folder in Xcode. A dialogue box should prompt you for import handling of these files into your project: check the Copy items into destination group's folder (if needed) check box, and select Create Folder References for any added folders. The Create Folder References option will preserve your directory structure in Xcode and on the device, as opposed to the soft folders Xcode normally uses that do not preserve your directory structure.

The Xcode groups option creates groups to help you organize your files during development. Note, though, that groups do not translate to directories when building: in your compiled application, all files will be found at the root level.

Verify your prompt looks like Figure 11-12 and click the Add button to continue.

Copy items into destination group's folder (if needed) Reference Type: Default t Text Encoding: Unicode (UTF-8)_ij

Copy items into destination group's folder (if needed) Reference Type: Default t Text Encoding: Unicode (UTF-8)_ij

O Recursively create groups for any added folders 0 Create Folder References for any added folders

Add To Targets r* ^ iWebkitDemo

Figure 11-12. Xcode file copy prompt

Then, to test-drive all the functionality available in iWebKit, implement the code from Listing 11-14 in your viewDidLoad method.

Listing 11-14. viewDidLoad Method

- (void)viewDidLoad {

// String representation of the URL

NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"index"^ ofType:@"html"];

//Create an URL object.

NSURL *url = [NSURL fileURLWithPath:urlAddress]; //URL Request Object

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView. [webView loadRequest:requestObj];

Follow the instructions in Chapter 2 to build and test your application shown in Figure 11-13.

Figure 11-13. iWebkit demo in UIWebViewSetting up Rhodes for iWebKit

Was this article helpful?

0 0
Living With Android

Living With Android

Get All The Support And Guidance You Need To Finally Be A Success At Using Android. This Book Is One Of The Most Valuable Resources In The World When It Comes To Playing With the Hottest Android Tablet.

Get My Free Ebook


Post a comment