/* 引入 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
1 个回复
s***@qq.com (作者)
已解决