s***@qq.com
s***@qq.com
  • 发布:2024-12-02 15:18
  • 更新:2024-12-04 17:23
  • 阅读:43

uts插件,ios端,无法触发代理

分类:uts
/* 引入 interface.uts 文件中定义的变量 */  
import { ScanCode, HWcanCodeOptions, HWcanSuccess } from '../interface.uts';  
import { HmsScanOptions, HmsDefaultScanViewController, HMSScanFormatTypeCode,DefaultScanDelegate } from "ScanKitFrameWork"  
class ScanDelegate implements DefaultScanDelegate{  
    defaultScanDelegate(resultDic:any[]){  
        DispatchQueue.main.async(execute = () : void => {  
            console.log(resultDic);  
        })  

    }  
}  
let delegate: ScanDelegate =  new ScanDelegate()  

class ScanCodeT{  
    scan(){  
        const scanFormatType = UInt32(HMSScanFormatTypeCode.ALL.rawValue)  
        const options = HmsScanOptions.init(scanFormatType = scanFormatType, photo = true)  

        const scanVc:HmsDefaultScanViewController = HmsDefaultScanViewController(defaultScanWithFormatType = options)  
        scanVc.defaultScanDelegate = delegate  
        console.log("Scan view controller initialized")  

        // 检查 scanVc 是否为 null  
        if (scanVc != null) {  
            const rootVC = UTSiOS.getCurrentViewController()  
            rootVC.present(scanVc, animated = true)  
            console.log(scanVc);  
        } else {  
            console.error("Failed to initialize HmsDefaultScanViewController")  
        }  
    }  

}  
export function scanCode(options : HWcanCodeOptions) {  
    // uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行  
    DispatchQueue.main.async(execute = () : void => {  

        // 创建 NativeCode 的实例  
        const nativeCode = new ScanCodeT()  

        // 设置回调函数  
        // nativeCode.scanResultCallback = (result) => {  
        //  console.log("Scan result received in UTS:", result)  
        // }  

        // 调用 scan 方法  
        nativeCode.scan()  
    })  
}

uts插件,iOS端,做的是华为统一扫码的功能,扫码完成之后一直触发不了代理,能帮看下是哪里写的不对吗?

这是统一扫码的文档https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/ios-default-view-0000001050414343

2024-12-02 15:18 负责人:无 分享
已邀请:
s***@qq.com

s***@qq.com (作者)

已解决

要回复问题请先登录注册