a90ff64e by ex

js

1 parent 83ce141f
1 var u = navigator.userAgent; 1 var u = navigator.userAgent;
2 var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 2 var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
3 var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 3 var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
4 4 layer.open()
5 function AppClient(appObj, isAndroid) { 5 function AppClient(appObj, isAndroid) {
6 this.appObj = appObj; 6 this.appObj = appObj;
7 this.isAndroid = isAndroid; 7 this.isAndroid = isAndroid;
8 }; 8 };
9 9
10 AppClient.prototype.closePage = function() {
11 if (this.isAndroid) {
12 this.appObj.closePageAction();
13 } else {
14 this.appObj.callHandler("closePageAction");
15 }
16 }
17 AppClient.prototype.login = function() {
18 if (this.isAndroid) {
19 this.appObj.closePageAction();
20 } else {
21 this.appObj.callHandler("closePageAction");
22 }
23 }
24 function isJson(str) { 10 function isJson(str) {
25 try { 11 try {
26 JSON.parse(str); 12 JSON.parse(str);
...@@ -86,33 +72,26 @@ AppClient.prototype.getGPS = function (callbackName, callback, jsonStr) { ...@@ -86,33 +72,26 @@ AppClient.prototype.getGPS = function (callbackName, callback, jsonStr) {
86 // time: 10 72 // time: 10
87 // }); 73 // });
88 // } 74 // }
89 var appClient = new AppClient(window.android, true); 75 // var appClient = new AppClient(window.android, true);
90 // layer.open({ 76 // layer.open({
91 // content: window.android, 77 // content: window.android,
92 // time: 2 78 // time: 2
93 // }) 79 // })
94 layer.open({ 80 // layer.open({
95 content: 'hah' , 81 // content: 'hah' ,
96 time: 2 82 // time: 2
97 }) 83 // })
98 bridge.registerHandler('postGPS', function(data, responseCallback) { 84 // bridge.registerHandler('postGPS', function(data, responseCallback) {
99 log('ObjC called testJavascriptHandler with', data) 85 // log('ObjC called testJavascriptHandler with', data)
100 var responseData = { 'Javascript Says':'Right back atcha!' } 86 // var responseData = { 'Javascript Says':'Right back atcha!' }
101 log('JS responding with', responseData) 87 // log('JS responding with', responseData)
102 responseCallback(responseData) 88 // responseCallback(responseData)
103 }) 89 // })
104 90
105 91
106 if(isAndroid) { 92 if(isAndroid || isiOS) {
107 layer.open({
108 content: 'Android' ,
109 time: 2
110 })
111 appClient = new AppClient(window.android, true);
112 // 此处可以调用一些init的方法
113 } else if(isiOS) {
114 layer.open({ 93 layer.open({
115 content: 'IOS' , 94 content: "isAndroid"+ isAndroid+'-' +"isiOS"+ isiOS,
116 time: 2 95 time: 2
117 }) 96 })
118 function setupWebViewJavascriptBridge(callback) { 97 function setupWebViewJavascriptBridge(callback) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!