0

我似乎在多用途应用程序中使用 Socket ScanAPI 时遇到了一些问题。我正在使用 GitHub 上的单入口 swift 示例代码,当我首次展示用于扫描的 VC 时,套接字扫描器和代码可以完美运行。

初始化类似于示例代码,除了我使用 ScanApiHelper() 而不是共享版本初始化 scanApiHelpher:

    var scanApiHelper = ScanApiHelper() 
scanApiHelperConsumer=NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: Selector("onScanApiHelperConsumer"), userInfo: nil, repeats: true)
        scanApiHelper.pushDelegate(self)
        scanApiHelper.open()

当我关闭 VC,然后再次显示它时,问题就出现了,我在 sktscanapilistenerthread 的 0x1005705c8 处崩溃:

0x1005705b4 <+1332>: bl     0x10058ab88               ; CSktScanAPI::NotifyError at CSktScanAPI.cpp:4639
    0x1005705b8 <+1336>: adrp   x8, 515
    0x1005705bc <+1340>: ldr    x1, [x8, #3296]
    0x1005705c0 <+1344>: ldr    x0, [sp, #8]
    0x1005705c4 <+1348>: bl     0x10062b338               ; symbol stub for: objc_msgSend
    0x1005705c8 <+1352>: add    x0, sp, #48               ; =48 
    0x1005705cc <+1356>: bl     0x100563308               ; CSktList::~CSktList at SktList.cpp:29
    0x1005705d0 <+1360>: add    x0, sp, #312              ; =312 
    0x1005705d4 <+1364>: bl     0x10057fa68               ; SktAccessoryEnumerator::~SktAccessoryEnumerator at SktAccessoryEnumerator.mm:45

初始化助手对象时SDK是否启动后台线程,因此重新初始化会导致崩溃?即辅助对象初始化必须在根VC 中进行吗?

4

2 回答 2

0

也许我在文档上遗漏了一些东西,但似乎对于涉及解除使用该 API 的 VC 的扫描仪 API 的任何使用,都需要 sharedhelper 对象,因为不可能多次初始化 ScanApiHelper var(它创建一个init 上的后台线程)。

于 2016-08-02T01:21:00.967 回答
0

您需要实现所有委托函数,以便 API 可以调用它们。即使它们是空的,API 也会调用它们,如果它们不存在,它将崩溃。

// MARK: SocketScanAPI methods
    @objc func onScanApiHelperConsumer(){

        if(!(scanApiHelper?.isScanApiOpen())!) {
            scanApiHelper?.open()
        }
        scanApiHelper?.doScanApiReceive()
    }

    public func onDeviceArrival(_ result: SKTRESULT, device deviceInfo: DeviceInfo!) {
        print("Main view device arrival:\(deviceInfo.getName() as String)")
    }

    public func onDeviceRemoval(_ deviceRemoved: DeviceInfo!) {
        print("Main view device removal:\(deviceRemoved.getName() as String)")
    }

    public func onDecodedDataResult(_ result: Int, device: DeviceInfo!, decodedData: ISktScanDecodedData!) {
        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)")
            NSLog("Decoded Data %@", string)
        }
    }

    public func onError(_ result: SKTRESULT) {
        print("Receive a ScanApi error: \(result)")
    }

    public func onErrorRetrievingScanObject(_ result: SKTRESULT) {
        print("Receive a ScanApi error while retrieving a ScanObject: \(result)")
    }

    public func onScanApiInitializeComplete(_ result: SKTRESULT) {
        print("Result of ScanAPI initialization: \(result)")
    }

    @objc public func onScanApiTerminated() {
        print("ScanAPI has terminated")
    }
于 2019-06-27T23:35:38.377 回答