Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
杨建斌
/
dy-wx2
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a90ff64e
authored
2018-09-01 14:53:47 +0800
by
ex
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
js
1 parent
83ce141f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
35 deletions
js/JSBridge.js
js/JSBridge.js
View file @
a90ff64
var
u
=
navigator
.
userAgent
;
var
isAndroid
=
u
.
indexOf
(
'Android'
)
>
-
1
||
u
.
indexOf
(
'Adr'
)
>
-
1
;
//android终端
var
isiOS
=
!!
u
.
match
(
/
\(
i
[^
;
]
+;
(
U;
)?
CPU.+Mac OS X/
);
//ios终端
layer
.
open
()
function
AppClient
(
appObj
,
isAndroid
)
{
this
.
appObj
=
appObj
;
this
.
isAndroid
=
isAndroid
;
};
AppClient
.
prototype
.
closePage
=
function
()
{
if
(
this
.
isAndroid
)
{
this
.
appObj
.
closePageAction
();
}
else
{
this
.
appObj
.
callHandler
(
"closePageAction"
);
}
}
AppClient
.
prototype
.
login
=
function
()
{
if
(
this
.
isAndroid
)
{
this
.
appObj
.
closePageAction
();
}
else
{
this
.
appObj
.
callHandler
(
"closePageAction"
);
}
}
function
isJson
(
str
)
{
try
{
JSON
.
parse
(
str
);
...
...
@@ -86,33 +72,26 @@ AppClient.prototype.getGPS = function (callbackName, callback, jsonStr) {
// time: 10
// });
// }
var
appClient
=
new
AppClient
(
window
.
android
,
true
);
//
var appClient = new AppClient(window.android, true);
// layer.open({
// content: window.android,
// time: 2
// })
layer
.
open
({
content
:
'hah'
,
time
:
2
})
bridge
.
registerHandler
(
'postGPS'
,
function
(
data
,
responseCallback
)
{
log
(
'ObjC called testJavascriptHandler with'
,
data
)
var
responseData
=
{
'Javascript Says'
:
'Right back atcha!'
}
log
(
'JS responding with'
,
responseData
)
responseCallback
(
responseData
)
})
//
layer.open({
//
content: 'hah' ,
//
time: 2
//
})
//
bridge.registerHandler('postGPS', function(data, responseCallback) {
//
log('ObjC called testJavascriptHandler with', data)
//
var responseData = { 'Javascript Says':'Right back atcha!' }
//
log('JS responding with', responseData)
//
responseCallback(responseData)
//
})
if
(
isAndroid
)
{
layer
.
open
({
content
:
'Android'
,
time
:
2
})
appClient
=
new
AppClient
(
window
.
android
,
true
);
// 此处可以调用一些init的方法
}
else
if
(
isiOS
)
{
if
(
isAndroid
||
isiOS
)
{
layer
.
open
({
content
:
'IOS'
,
content
:
"isAndroid"
+
isAndroid
+
'-'
+
"isiOS"
+
isiOS
,
time
:
2
})
function
setupWebViewJavascriptBridge
(
callback
)
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment