iPhone Dev: UIWebView baseUrl to resources in Documents folder not App bundle

后端 未结 3 1942
-上瘾入骨i
-上瘾入骨i 2020-12-01 04:52

Greetings! Can anyone please kindly assist me finding a way around the following:

  • load an html into a UIWebView using loadHTMLString and incl
3条回答
  •  被撕碎了的回忆
    2020-12-01 05:16

    To get the path to the document directory:

    NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"index.xml"];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]]
    

    The easiest way to have everything working, is to simply load your index.html from the document directory instead of loading a string. Otherwise set the baseUrl to the document directory.

提交回复
热议问题