UIWebView display locally stored website (HTML, images, Javascript)

后端 未结 6 2147
栀梦
栀梦 2020-12-08 12:50

I\'ve looked EVERYWHERE for this, can\'t find anything. I basically need to store an entire website inside of my iPhone for some interesting reasons. Regardless I can\'t fig

6条回答
  •  轮回少年
    2020-12-08 12:57

    My attempt was to run an entire web page out of the Xcode project file. To do that you must:

    1. When importing the file select "Create folder references for any added folders".

    2. Set up the web view, but make sure you set the relative path as previously mentioned.

      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];
      

提交回复
热议问题