feat(data):修改判断移动端平台的条件

master
beichen 5 years ago
parent 9eefad5519
commit a82b2159d8
  1. 4
      JSBridgeAndroidJava/app/src/main/java/com/beichen/jsbridgeandroidjava/MainActivity.java
  2. 2
      JSBridgeAndroidKotlin/app/src/main/java/com/beichen/jsbridgeandroidkotlin/MainActivity.kt
  3. 4
      JSBridgeH5/src/App.js
  4. 6
      JSBridgeH5/src/index.js
  5. 4
      JSBridgeIOSOC/JSBridgeIOSOC/ViewController.m
  6. 4
      JSBridgeIOSSwift/JSBridgeIOSSwift/ViewController.swift

@ -22,6 +22,8 @@ import com.github.lzyzsd.jsbridge.CallBackFunction;
public class MainActivity extends AppCompatActivity implements View.OnClickListener { public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private BridgeWebView mWebView; private BridgeWebView mWebView;
// URL 网络请求地址
// TODO: 请替换成页面的 url 地址
private static final String URL = "http://xxx.xxx.xxx.xxx:xxxx/"; private static final String URL = "http://xxx.xxx.xxx.xxx:xxxx/";
long exitTime = 0; long exitTime = 0;
@ -65,7 +67,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// 进行缩放 // 进行缩放
mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setBuiltInZoomControls(true);
// 设置UserAgent // 设置UserAgent
mWebView.getSettings().setUserAgentString(mWebView.getSettings().getUserAgentString() + "android"); mWebView.getSettings().setUserAgentString(mWebView.getSettings().getUserAgentString() + "app");
// 设置不用系统浏览器打开,直接显示在当前WebView // 设置不用系统浏览器打开,直接显示在当前WebView
mWebView.setWebChromeClient(new WebChromeClient()); mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new MyWebViewClient(mWebView)); mWebView.setWebViewClient(new MyWebViewClient(mWebView));

@ -61,7 +61,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
// 进行缩放 // 进行缩放
mWebView!!.settings.builtInZoomControls = true mWebView!!.settings.builtInZoomControls = true
// 设置UserAgent // 设置UserAgent
mWebView!!.settings.userAgentString = mWebView!!.settings.userAgentString + "android" mWebView!!.settings.userAgentString = mWebView!!.settings.userAgentString + "app"
// 设置不用系统浏览器打开,直接显示在当前WebView // 设置不用系统浏览器打开,直接显示在当前WebView
mWebView!!.webChromeClient = WebChromeClient() mWebView!!.webChromeClient = WebChromeClient()
mWebView!!.webViewClient = MyWebViewClient(mWebView!!) mWebView!!.webViewClient = MyWebViewClient(mWebView!!)

@ -6,7 +6,9 @@ import Cookie from 'js-cookie';
import styles from './App.less'; import styles from './App.less';
const isAndroid = navigator.userAgent.endsWith('android'); const u = navigator.userAgent;
// Android终端
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
export default (props) => { export default (props) => {

@ -17,7 +17,11 @@ import App from './App';
* 安卓才可以正常调用 H5 的回调函数并且 H5 调用安卓成功后的回调函数也可以正常执行了 * 安卓才可以正常调用 H5 的回调函数并且 H5 调用安卓成功后的回调函数也可以正常执行了
*/ */
const isAndroid = navigator.userAgent.endsWith('android'); const u = navigator.userAgent;
// Android终端
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
// IOS 终端
const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
/** /**
* Android 与安卓交互时 * Android 与安卓交互时

@ -100,8 +100,8 @@
// TODO: 请替换成页面的 url 地址 // TODO: 请替换成页面的 url 地址
NSString *URLSTR = @"http://xxx.xxx.xxx.xx:xxxx"; NSString *URLSTR = @"http://xxx.xxx.xxx.xx:xxxx";
self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 360) configuration:_webConfig]; self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 360) configuration:_webConfig];
// 设置 UserAgent 后缀,这里设置为 ios 用于在 H5 端进行区分 IOS 平台还是 Android 平台 // 设置 UserAgent 后缀
_webView.customUserAgent = [NSString stringWithFormat:self.webView.customUserAgent, @"ios"]; _webView.customUserAgent = [NSString stringWithFormat:self.webView.customUserAgent, @"app"];
_webView.UIDelegate = self; _webView.UIDelegate = self;
_webView.navigationDelegate = self; _webView.navigationDelegate = self;
NSURL *url = [NSURL URLWithString:URLSTR]; NSURL *url = [NSURL URLWithString:URLSTR];

@ -92,8 +92,8 @@ class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {
// TODO: url // TODO: url
let URLSTR = "http://xxx.xxx.xxx.xxx:xxxx" let URLSTR = "http://xxx.xxx.xxx.xxx:xxxx"
webView = WKWebView(frame: CGRect(x: 0, y: 0, width: view.bounds.size.width, height: 420), configuration: webConfig!) webView = WKWebView(frame: CGRect(x: 0, y: 0, width: view.bounds.size.width, height: 420), configuration: webConfig!)
// UserAgent ios H5 IOS Android // UserAgent
webView.customUserAgent = String(format: webView!.customUserAgent!, "ios") webView.customUserAgent = String(format: webView!.customUserAgent!, "app")
webView.uiDelegate = self webView.uiDelegate = self
webView.navigationDelegate = self webView.navigationDelegate = self
let url = URL(string: URLSTR) let url = URL(string: URLSTR)

Loading…
Cancel
Save