一 什么是webViewjavascripBridge?
WebViewJavascriptBridge是移动UIView和Html交互通信的桥梁,用作者的话来说就是实现java(ios为oc)和js的互相调用的桥梁。替代了WebView的自带的JavascriptInterface的接口,使得我们的开发更加灵活和安全。
WebViewJavascriptBridge
for Android
https://github.com/jesse01/WebViewJavascriptBridge
WebViewJavascriptBridge for iOS/OSX
https://github.com/marcuswestin/WebViewJavascriptBridge
注意:使用4.1.5版才能跟安卓的保持一致:
pod 'WebViewJavascriptBridge','4.1.5'
二 什么是X5
- TBS2.1基于Android 5.0 WebView Blink内核(M37版本)适配定制优化,适配Android全部主流平台,可以支持移动应用App在所有Android手机上使用Blink的技术能力。TBS2.1支持Service Worker,可以帮助Web应用后台运行,提供离线访问等原生App应用体验。此外,TBS2.1在H5/CSS3支持,安全,可靠,性能方面有进一步提升。TBS2.1已经发布,将逐步在各客户端中静默升级,用户终端无需更新微信、手机QQ、QQ空间即可使用最新的TBS2.1Blink内核。
三 接入注意事项
1、X5与WebViewJavascriptBridge
private class MyWebChromeClient extends WebChromeClient { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } @Override public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { return super.onJsConfirm(view, url, message, result); } @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { return super.onJsPrompt(view, url, message, defaultValue, result); } @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); super.onGeolocationPermissionsShowPrompt(origin, callback); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { if (mUploadMessage != null) return; Log.e("openFileChooser", "openFileChooser"); mUploadMessage = uploadMsg; selectImage(); // Intent i = new Intent(Intent.ACTION_GET_CONTENT); // i.addCategory(Intent.CATEGORY_OPENABLE); // i.setType("*/*"); // startActivityForResult( Intent.createChooser( i, "File Chooser" ), FILECHOOSER_RESULTCODE ); } // For Android < 3.0 public void openFileChooser(ValueCallback<Uri> uploadMsg) { openFileChooser(uploadMsg, ""); } // For Android > 4.1.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg, acceptType); } }
- GeolocationPermissions.Callback 替换为 GeolocationPermissionsCallback
修改为:
private class MyWebChromeClient extends WebChromeClient { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } @Override public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { return super.onJsConfirm(view, url, message, result); } @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { return super.onJsPrompt(view, url, message, defaultValue, result); } @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissionsCallback callback) { callback.invoke(origin, true, false); super.onGeolocationPermissionsShowPrompt(origin, callback); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { if (mUploadMessage != null) return; Log.e("openFileChooser", "openFileChooser"); mUploadMessage = uploadMsg; selectImage(); // Intent i = new Intent(Intent.ACTION_GET_CONTENT); // i.addCategory(Intent.CATEGORY_OPENABLE); // i.setType("*/*"); // startActivityForResult( Intent.createChooser( i, "File Chooser" ), FILECHOOSER_RESULTCODE ); } // For Android < 3.0 public void openFileChooser(ValueCallback<Uri> uploadMsg) { openFileChooser(uploadMsg, ""); } // For Android > 4.1.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg, acceptType); } }
2,X5与百度地图网页版
地图加载慢或者加载不出来的情况 ,发现是因为
1、x5没能打开GPS定位权限,建议提示将GPS、WiFi、4G网络定位都打开。
2、第一次加载百度地图去下载的网页元素太大