2015-07-20 43 views
2

當我使用下面的代碼打開嵌入式html文件時。它不能觸發委託:[ -webView:shouldStartLoadWithRequest:navigationType:];UIWebView不適用於file:///private/var/..../(myapp).app/www/index.html

NSURL *url = [NSURL URLWithString:@"file:///private/var/..../(myapp).app/www/index.html"]; 

NSMutableURLRequest *urlReq = [NSMutableURLRequest requestWith:url 
           cachePolicy:NSURLRequestUseProtocolCachePolicy 
           timeoutInterval: 60.0f]; 

[webview loadRequest:urlReq]; 

我怎樣才能得到這個要求?

回答

0

它是您的本地機器路徑,而不是模擬器/ iOS路徑。對於iOS,只有兩個目錄文件資源:

  • 一個NSBundle
  • 文檔目錄

在你的情況,你的WWW文件夾是包文件夾,這樣,試試這個:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]]; 
+0

路徑來自NSBundle類,實際路徑指向myapp.app/www/。這僅僅是iOS8的工作。 – Ericpoon

相關問題