2016-10-19 2 views
1

Deux questions:wkwebview exécuter html local (dans le document) a reçu une URL inattendue du processus Web

fichiers 1.Accédez comme .js Css devraient par fullPath que le code index.html vous voir;

2.Lorsque codes de index.html courent à "document.body.appendChild (iFrame)", course simulateur à blanc, et le journal de Xcode:

a reçu une URL inattendue du processus Web: "file:///Utilisateurs/John_Chen/Library/Developer/CoreSimulator/Devices/20ABEC24-78BD-4577-9AA5-35CB1520F620/data/Containers/Data/Application/30A53A36-4A05-4491-A400-CEBF5F9E7D21/Documents/test/2.html ' Reçu un message non valide "WebPageProxy.DecidePolicyForNavigationAction" à partir du processus Web.

Quelqu'un peut-il aider? TKS!

Code iOS:

1.Unzip test.zip au document:

- (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 charge 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; 
} 

files in document directory codes in index.html

Répondre

1

I pense que c'est parce que vous n'utilisez pas la méthode loadFileURL:allowingReadAccessToURL: Le deuxième argument serait le répertoire dans lequel le html se trouve.

+0

Je l'avais résolu sur le gitHub pour raison que bug de WKWebview.So je le remplace par UIWebView. – JohnChen

+0

Je pense que vous devriez essayer encore une fois, car UIWebView est tellement plus lent que WKWebView –