UIWebView displays a locally stored website (HTML, images, Javascript)

I looked EVERYWHERE for this, I can not find anything. I basically need to store the entire site inside my iPhone for some interesting reasons. No matter what, I cannot figure out how to display it correctly in my UIWebView.

EDIT: I have to clarify, I can download the source HTML file, and I ran all the paths to be local, except that nothing is connected.

Here is the code

self.dataDetectorTypes = UIDataDetectorTypeLink;
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self loadRequest:request];

index.html has a bunch <script type="text/javascript" src="somescript.js">

None of the JS code is executed

+5
source share
6 answers

, HTML . , (.js,.css ) . , , , - , js .. .

, , , - , html, js css URL-. - , UIWebView , , . , , , .

html XCode, , , () , " " " " . "

- , , XCode , , . , , , , .

-, , , . , - , - (, "-" ):

NSString *path = [[NSBundle mainBundle] 
                 pathForResource:@"index" ofType:@"html" 
                     inDirectory:@"webpages"];

, , - html BASE. , -.

+13

, :

NSURL *url = [NSURL fileURLWithPath:path];

baseURL, .html , javascript, css, images .., .

:

url = [NSURL URLWithString: [path lastPathComponent] 
             relativeToURL: [NSURL fileURLWithPath: [path stringByDeletingLastPathComponent] 
                                       isDirectory: YES]];

, "styles.css" index.html, IFF, .html.

+7

:

myWebView.dataDetectorTypes = UIDataDetectorTypeLink
+1

, .js , . Xcode .

0

pathFor .

0

, - Xcode. :

  • " ".

  • Customize the web view, but make sure you set the relative path as mentioned earlier.

    NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" 
                                            ofType:@"html" 
                                            inDirectory:@"Directory"];
    
    NSURL *url = [NSURL URLWithString:[path lastPathComponent] relativeToURL:
          [NSURL fileURLWithPath: [path stringByDeletingLastPathComponent] 
                 isDirectory:YES]];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [self.currentWebView loadRequest:request];
    
0
source

All Articles