Open wakatanka opened 7 years ago
Replace("/", "//")
will replace every /
in the string so it should be removed. The following modification works for UIWebView (enableWKWebView:false
).
diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs
index 9ec7973..f8ab5dc 100644
--- a/sample/Assets/Scripts/SampleWebView.cs
+++ b/sample/Assets/Scripts/SampleWebView.cs
@@ -104,7 +104,10 @@ public class SampleWebView : MonoBehaviour
}
System.IO.File.WriteAllBytes(dst, result);
if (ext == ".html") {
- webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
+ //webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
+ webViewObject.LoadHTML(
+ System.Text.Encoding.UTF8.GetString(result),
+ "file://" + Application.persistentDataPath.Replace(" ", "%20") + "/");
break;
}
}
However, WKWebView forbits file://
URLs for loadHtmlString:baseURL:
so it won't load your images. For avoiding the issue, please put the main html under Application.persistentDataPath
and call LoadURL()
as done in the sample app.
Hi, I just stumbled upon this.
Does it mean that this package won't work with file:// URLs embedded in a web page as well, unless you switch to UIWebView? I am asking because WKWebView is required by Apple nowadays.
There is a flag to tell WKWebView that it may allow this: https://bugs.webkit.org/show_bug.cgi?id=154916#c7
Is this implemented in this package?
Also wondering how the situation is for Android 10.
(We are currently using UniWebView and have problems with exact this. We need access to a local file that is actually a screen shot of the native Augmented Reality camera. It seems as if this worked in UniWebView before, but now is broken. I was wondering if we could use your package instead.)
This plugin just utilizes native Android WebView and/or iOS WKWebView/UIWebView components. The allowFileAccessFromFileURLs
seems to work but is not officially supported.
However, as described above, WKWebView (since iOS9) allows to load local files if you use LoadURL()
instead of LoadHTML()
. The sample app in this repository actually loads a local sample.html by LoadURL()
, and sample.js and sample.jpg, both are referred in sample.html, are correctly loaded.
Please note the sample app first writes these files into Applicaiton.persistentDataPath
and then load sample.html. You can therefore dynamically generate any webview content locally under Applicaiton.persistentDataPath
for your webview.
Android 10 seems to have many troubles about WebView, but these should be reduced by updating Android System WebView from Google Play.
Hi, i load my html from an sqlite database on iOS, and all the images relative to this HTML in downloaded on the device in the persistentdatapath. Using
The html il loaded correctly, but i can't see any images, are a there a workaround for this?
thanks