套接字条码扫描器sdk在重新加载iOS中的ViewController时崩溃

时间:2016-07-31 06:50:51

标签: ios swift barcode-scanner socketscan

我似乎在多功能应用程序中使用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中进行辅助对象初始化?

2 个答案:

答案 0 :(得分:0)

也许我在文档上遗漏了一些东西,但似乎对于任何使用扫描程序API的问题都涉及解雇使用API​​的VC,所以sharedhelper对象是必需的,因为它无法初始化ScanApiHelper var多次(它在init上创建一个后台线程)。

答案 1 :(得分: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")
    }