Objective-C

From ETC Public Wiki
Revision as of 13:22, 2 May 2011 by Hyungchu (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to deploy web application to the iPad :

In order to publish our application in the app store, we need to create Xcode project. However, our platform is a game based on web page, so we need to wrap our program to looks like native application. Fortunately, using UIWebView class which is mobile Safari browser view supported by Xcode, we could wrap our game as a normal iPad application. Once we set which web page should be loaded first in ViewController implementation file, our program can be executed from start. To make our web game looks like normal game, we need to remove browser feature such as scaling, status bar and scrolling. Using meta tags, we could eliminate these functions.

To use UIWebView in ViewController.m file.

@synthesize WebView;
@- (void)viewDidLoad {
@ [super viewDidLoad];
@// To connect online
@// NSString *urlAddress = @"http://YourWebAddress";
@// NSURL *url = [NSURL URLWithString: urlAddress];
@// NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
@// [webView loadRequest:requestObj];
@// To connect offline
@ NSString *filePath = [[NSBundle mainBundle] pathForResource:@"yourFileName" ofType:@"html"];
@ NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
@ if (htmlData) {
@ NSBundle *bundle = [NSBundle mainBundle];
@ NSString *path = [bundle bundlePath];
@ NSString *fullPath = [NSBundle pathForResource:@"yourFileName" ofType:@"html" inDirectory:path];
@ [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:fullPath]]];
@ }
@}

To remove URL and button bar

<meta name="apple-mobile-web-app-capable" content="yes" />

To prevent scaling

<meta name="viewport" content="user-scalable=no, width=device-width" />

To prevent scrolling we use Javascript.

Function Block(event){
event.preventDefault();}

To detect touch event we added event listener for touching using Javascript.

touchstart - To detect touch start touchmove - To detect touch move touchend - To detect touch end