我有一个解决方案,但我不能保证它也适合你。 但我认为你可以尝试一下。
└─┬WKWebLoadLocalJS
|
└─┬WKWebLoadLocalJS
|
├─┬framework7-master
| |
| └─┬kitchen-sink
| |
| └─┬core
| |
| └──index.html
|
├──AppDelegate.h
|
├──AppDelegate.m
|
├──ViewController
|
|
└ …
- (void)loadLocalJS {
NSFileManager *fileManager = [NSFileManager defaultManager];
//Folder path in the project
NSString *directoryPath = [[NSBundle mainBundle] pathForResource:@"framework7-master" ofType:@""];
//Tmp cache folder path
NSString *tmpPath = NSTemporaryDirectory();
//Create a newDir (any name) folder under the tmp folder
NSString *newDir =@"newDir";
[fileManager createDirectoryAtPath:[tmpPath stringByAppendingString:newDir] withIntermediateDirectories:YES attributes:nil error:nil];
//The path to the newDir folder in tmp
NSString *tmp_newDir_path = [tmpPath stringByAppendingString:newDir];
//Copy folder to the tmp/newDir path
NSError*error;
NSString*txtPath =[tmp_newDir_path stringByAppendingPathComponent:@"framework7-master"];
if(![fileManager fileExistsAtPath:txtPath]){
NSLog(@"***** Copy folder to the tmp/newDir path:%d*****",[fileManager copyItemAtPath:directoryPath toPath:txtPath error:&error]);
}
//Tmp/newDir/FeedbackH5/pages/feedback.html full path
NSString *tmp_newDir_Feedback = [tmp_newDir_path stringByAppendingString:@"/framework7-master/kitchen-sink/core/index.html"];
//Convert path to URL
NSURL *feedbackURL = [NSURL fileURLWithPath:tmp_newDir_Feedback];
//WKWebView
[self.web loadRequest:[NSURLRequest requestWithURL:feedbackURL]];
}
如果你不明白,你可以看到这个例子 。
我希望它可以帮到你。