Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
web-lib
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑磊
web-lib
Commits
e47e1e2f
Commit
e47e1e2f
authored
Apr 10, 2024
by
郑磊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新原生api调用方式
parent
1fee7a3a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
20 deletions
+16
-20
native-api.ts
src/app/native-api.ts
+16
-20
No files found.
src/app/native-api.ts
View file @
e47e1e2f
...
...
@@ -16,11 +16,11 @@ declare global {
}
}
function
callIosApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
function
callIosApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
function
callIosApi
<
T
>
(
name
:
string
,
...
args
:
any
[]):
boolean
{
function
callIosApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
void
function
callIosApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
void
function
callIosApi
<
T
>
(
name
:
string
,
...
args
:
any
[]):
void
{
if
(
typeof
window
.
webkit
?.
messageHandlers
[
name
]?.
postMessage
===
'function'
)
{
return
false
return
}
let
params
:
any
=
undefined
...
...
@@ -38,14 +38,13 @@ function callIosApi<T>(name: string, ...args: any[]): boolean {
}
window
.
webkit
.
messageHandlers
[
name
].
postMessage
(
params
??
true
)
return
true
}
function
callAndroidApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
function
callAndroidApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
function
callAndroidApi
(
name
:
string
,
...
args
:
any
[]):
boolean
{
function
callAndroidApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
void
function
callAndroidApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
void
function
callAndroidApi
(
name
:
string
,
...
args
:
any
[]):
void
{
if
(
typeof
window
.
liveapp
[
name
]
!==
'function'
)
{
return
false
return
}
let
params
:
any
=
undefined
...
...
@@ -57,17 +56,14 @@ function callAndroidApi(name: string, ...args: any[]): boolean {
ack
=
args
[
1
]
}
if
(
typeof
ack
===
'function'
)
{
// @ts-ignore
window
[
name
]
=
ack
}
const
invokeArgs
:
Parameters
<
(
typeof
window
.
liveapp
)[
string
]
>
=
[]
if
(
typeof
params
!==
'undefined'
&&
params
!==
null
)
{
invokeArgs
.
push
(
JSON
.
stringify
(
params
))
}
window
.
liveapp
[
name
](...
invokeArgs
)
return
true
const
result
=
window
.
liveapp
[
name
](...
invokeArgs
)
if
(
typeof
ack
===
'function'
)
{
ack
(
result
)
}
}
const
isiOS
=
!!
navigator
.
userAgent
.
match
(
/
\(
i
[^
;
]
+;
(
U;
)?
CPU.+Mac OS X/
)
//ios终端
...
...
@@ -77,10 +73,10 @@ const isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) //ios
* @param name
* @param params
*/
export
function
callNativeApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
export
function
callNativeApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
export
function
callNativeApi
(
name
:
string
,
...
args
:
any
[]):
boolean
{
return
isiOS
?
callIosApi
(
name
,
...
args
)
:
callAndroidApi
(
name
,
...
args
)
export
function
callNativeApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
void
export
function
callNativeApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
void
export
function
callNativeApi
(
name
:
string
,
...
args
:
any
[]):
void
{
isiOS
?
callIosApi
(
name
,
...
args
)
:
callAndroidApi
(
name
,
...
args
)
}
export
namespace
NativeApi
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment