gpt4 book ai didi

ios - 如何使用 API 断开/停止扫描 Socket Mobile 扫描器?

转载 作者:行者123 更新时间:2023-11-28 06:07:25 26 4
gpt4 key购买 nike

在我的应用程序中集成了 Socket Mobile Scanner 来扫描库存项目,我的要求是停止扫描仪的扫描,直到应用程序搜索/检查项目存在。

如果最近的项目不是有效项目,Scanner 应该停止扫描。

我使用了下面的代码:

/// here scanApiHelper is instance of ScanApiHelper 
scanApiHelper?.pop(self)
scanApiHelper?.close()

最佳答案

您可以使用一种数据确认模式来涵盖这种情况。在此模式下,除非您明确确认来自应用程序的数据,否则触发器会锁定一段时间。触发器锁定时间可以配置。另一种可能性是暂时禁用触发器并在您的应用准备就绪时重新启用它。

看看 github singleentry-ios ( https://github.com/SocketMobile/singleentryswift-ios ) 它有一个数据确认的代码示例:

    func onDecodedDataResult(_ result: Int, device: DeviceInfo!, decodedData: ISktScanDecodedData!) {
print("onDecodedDataResult in the detail view")
if result==ESKT_NOERROR {
let rawData = decodedData.getData()
let rawDataSize = decodedData.getSize()
let data = Data(bytes: UnsafePointer<UInt8>(rawData!), count: Int(rawDataSize))
print("Size: \(rawDataSize)")
print("data: \(data)")
let str = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
let string = str as! String
print("Decoded Data \(string)")
self.decodedData.text = string
// this code can be removed if the application is not interested by
// the host Acknowledgment for the decoded data
#if HOST_ACKNOWLEDGMENT
ScanApiHelper.shared().postSetDataConfirmationOkDevice(device, target: self, response: #selector(onSetDataConfirmation(_:)))
#endif
}
}

#if HOST_ACKNOWLEDGMENT
func onSetDataConfirmation(_ scanObj: ISktScanObject){
let result = scanObj.msg().result()
if result != ESKT_NOERROR {
print("error trying to confirm the decoded data: \(result)")
}
}
#endif

扫描仪需要配置一次为此模式:

    #if HOST_ACKNOWLEDGMENT
scanApiHelper?.postGetLocalAcknowledgmentDevice(deviceInfo, target: self, response: #selector(onGetLocalAcknowledgment(_:)))
scanApiHelper?.postGetDecodeActionDevice(deviceInfo, target: self, response: #selector(onGetDecodeAction(_:)))
#else // to remove the Host Acknowledgment if it was set before
scanApiHelper?.postGetLocalAcknowledgmentDevice(deviceInfo, target: self, response: #selector(onGetLocalAcknowledgmentLocalAck(_:)))
scanApiHelper?.postGetDecodeActionDevice(deviceInfo, target: self, response: #selector(onGetDecodeActionLocalAck(_:)))
#endif

希望对您有所帮助。

关于ios - 如何使用 API 断开/停止扫描 Socket Mobile 扫描器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47831860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com