2012-04-26 30 views
1

我想知道是否可以從iOS設備的硬盤驅動器運行HTML頁面,只使用Objective-C作爲HTML頁面的視圖端口並使HTML頁面成爲應用程序的實際接口。這可能嗎?作爲應用程序的HTML,Javascript和CSS

感謝,

Odinulf

+2

看看PhoneGap和/或Sencha Touch 2.兩者都這樣做。 – 2012-04-26 15:29:07

回答

2

的IOS創建以下文件:

#import "WrapperViewController.h" 

@implementation WrapperViewController 

- (void) viewDidLoad 
{ 
    NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *path  = [bundle bundlePath]; 
    NSString *fullpath = [NSBundle pathForResource:@"index" ofType:@"htm" inDirectory:path]; 
    [webView loadRequest:[NSURLRequest requestWithURL: [NSURL fileURLWithPath:fullPath]]]; 
} 

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation 
{ 
    return YES; 
} 
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation 
{ 
    webView.scalesPageToFit = YES; 
    WebView.backgroundColor = [UIColor blackColor]; 
} 

- (void) didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

- (void) dealloc 
{ 
    [super dealloc]; 
} 
@end 

(我得到這個直出書 「HTML5的iOS和Android:初學者指南」 的[388至390頁])

this是你如何做它的android。

希望這會有所幫助!

+1

返回'shouldAutoRotate ...'函數中的某些內容。 – 11684 2012-04-26 19:17:17

+0

@ 11684 - 感謝您的注意,我解決了它 – Ephraim 2012-04-26 19:35:17

0

我與Phonegap合作過,並且對它印象深刻。還沒有嘗試過與IOS,但這裏的鏈接PhoneGap

1

是的,這是可能的。您需要查看UIWebView,然後在本地目錄中加載指向HTML文件的請求,而不是網址。所有的網頁都需要添加到應用程序包中。

UIWebView *webview; 
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"page_name" ofType:@"html"]isDirectory:NO]]] 
+0

這是否有任何限制?如果您使用文件協議,桌面瀏覽器通常以殘缺模式運行。移動Safari的行爲是否相似? – 2012-04-26 15:38:26

+0

我注意到的唯一問題是讓webview識別子目錄中的文件(如果這是你如何設置你的網站,並且大多數都是以這種方式設置的話)。對此的一個答案是將所有文件放在同一個目錄中(我知道一個痛苦)。還必須有其他更好的解決方案 – achi 2012-04-26 15:57:08

相關問題