uts插件iOS
export type CallA = {
onSuccess: (a: string) => void
onFail: (e: string) => void
}
export class LgTest {
private host : string = '';
private port : number = 0;
private callA : CallA | null = null
constructor(host: string, port: number) {
this.host = host
this.port = port
}
@UTSJS.keepAlive
public setCallA(call : CallA) : void {
this.callA = call
}
public mCallASuccess() : void {
if (this.callA !== null) {
this.callA!.onSuccess('调用了success')
}
}
public mCallAFail() : void {
if (this.callA !== null) {
this.callA!.onFail('调用了onFail')
}
}
public testA() : string {
return '232323testA23232323'
}
}
uts使用代码
import { LgTest } from '@/uni_modules/lg-test'
let lgTestIns: LgTest | null = null
const initTest = () => {
lgTestIns = new LgTest('192.168.0.0', 8080)
}
const setCall = () => {
if (lgTestIns) {
const callA = {
onSuccess: (a: string) => {
console.log('lgTestIns onSuccess回调了', a)
},
onFail: (e: string) => {
console.log('lgTestIns onFail回调了', e)
}
}
lgTestIns.setCallA(callA)
}
}
const callSuccess = () => {
if (lgTestIns) {
lgTestIns!.mCallASuccess()
}
}
const callFail = () => {
if (lgTestIns) {
lgTestIns!.mCallAFail()
}
}
const callTestA = () => {
if (lgTestIns) {
console.log('callTestA', lgTestIns!.testA())
}
}
1 个回复
d***@lgmg.com.cn (作者)
离线包使用的是4.66版本