두 질문에 예상치 못한 URL 수상wkwebview 실행 로컬 HTML은 웹 과정에서
할수 있도록 팝업 된 index.html의 코드는 "document.body.appendChild (iframe이)", 빈에 시뮬레이터 실행하려면 실행하고, 엑스 코드 로그 : '파일 :
예기치 않은 웹 과정에서 URL을 수신///Users/john_Chen/Library/Developer/CoreSimulator/Devices/20ABEC24-78BD-4577-9AA5-35CB1520F620/data/Containers/Data/Application/30A53A36-4A05-4491-A400-CEBF5F9E7D21/Documents/test/2.html ' 웹 프로세스에서 "WebPageProxy.DecidePolicyForNavigationAction"이라는 잘못된 메시지를 받았습니다.
아무도 도와 드릴 수 있습니까? TKS!
아이폰 OS 코드 :
- (void)copyFloderToSandbox
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *originalPlayerPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"zip"];
NSString *originalMovi_01Path = [[NSBundle mainBundle] pathForResource:@"movi_01" ofType:@"zip"];
NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *PDoc = [documentPath stringByAppendingPathComponent:@"test"];
NSString *MDoc = [documentPath stringByAppendingPathComponent:@"movi_01"];
if (![fm fileExistsAtPath:PDoc])
{
[SSZipArchive unzipFileAtPath:originalPlayerPath toDestination:documentPath];
}
if (![fm fileExistsAtPath:MDoc])
{
[SSZipArchive unzipFileAtPath:originalMovi_01Path toDestination:documentPath];
}
}
2.WKWebView 부하 index.html을 :
- (void)viewDidLoad {
[super viewDidLoad];
[self copyFloderToSandbox];
self.webView = [[WKWebView alloc]initWithFrame:self.view.bounds configuration:[self configWeb]];
_webView.navigationDelegate = self;
_webView.UIDelegate = self;
[self.view addSubview:_webView];
NSString *playerPath = [OMDBManager getLocalDataFilePathWithPathComponent:@"test"];
NSString *html = [playerPath stringByAppendingPathComponent:@"index.html"];
NSString *moviePath = [OMDBManager getLocalDataFilePathWithPathComponent:@"movi_01"];
NSString *moviParameter = [NSString stringWithFormat:@"movieroot=%@",playerPath];
NSString *playParameter = [NSString stringWithFormat:@"playerroot=%@",playerPath];
NSString *baseString = [NSString stringWithFormat:@"%@?%@&%@",html,moviParameter,playParameter];
NSURL *baseUrl = [NSURL fileURLWithPath:baseString isDirectory:YES];
NSString *htmlContent = [NSString stringWithContentsOfFile:html encoding:NSUTF8StringEncoding error:nil];
[_webView loadHTMLString:htmlContent baseURL:baseUrl];
}
- (WKWebViewConfiguration *)configWeb
{
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc]init];
configuration.preferences = [[WKPreferences alloc]init];
configuration.preferences.minimumFontSize = 18;
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.userContentController = [[WKUserContentController alloc]init];
[configuration.userContentController addScriptMessageHandler:self name:@"readJsonFile"];
return configuration;
}
저는 WKWebview의 버그 때문에 gitHub에서 해결했습니다. 그래서 UIWebView로 대체했습니다. – JohnChen
UIWebView가 WKWebView보다 훨씬 느리기 때문에 다른 시도를 해봐야한다고 생각합니다. –