修改iOS FlutterWebviewPlugin.m 源代码
- (void)navigate:(FlutterMethodCall*)call {
if (self.webview != nil) {
NSString *url = call.arguments[@"url"];
NSNumber *withLocalUrl = call.arguments[@"withLocalUrl"];
if ( [withLocalUrl boolValue]) {
NSURL *htmlUrl = [NSURL fileURLWithPath:url isDirectory:false];
NSString *localUrlScope = call.arguments[@"localUrlScope"];
//为减少对三方插件的修改,加载本地html,文件名暂时只支持命名为名index
NSURL *findUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Frameworks/App.framework/flutter_assets/%@", [[NSBundle mainBundle] bundlePath], url]];
NSLog(@"Debug >>>> %@", findUrl);
NSString *loadUrl = [findUrl.absoluteString stringByReplacingOccurrencesOfString:@"index.html" withString:url];
htmlUrl = [NSURL URLWithString:loadUrl];
NSLog(@"Debug >>>> load url %@", htmlUrl);
if (@available(iOS 9.0, *)) {
if(localUrlScope.class == NSNull.class || localUrlScope == nil) {
[self.webview loadFileURL:htmlUrl allowingReadAccessToURL:htmlUrl];
}
else {
NSURL *scopeUrl = [NSURL fileURLWithPath:localUrlScope];
[self.webview loadFileURL:htmlUrl allowingReadAccessToURL:scopeUrl];
}
} else {
@throw @"not available on version earlier than ios 9.0";
}
} else {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
NSDictionary *headers = call.arguments[@"headers"];
if (headers != nil) {
[request setAllHTTPHeaderFields:headers];
}
[self.webview loadRequest:request];
}
}
}
参考地址 :https://blog.csdn.net/u014665060/article/details/105315854
网友评论