EASession stream function doesn't fire

被刻印的时光 ゝ 提交于 2019-12-11 14:24:27

问题


I have MFi device(RFID reader) and I'm trying to catch scanned tags in my app. So I use EAAccessorymanager to get the shared accessory and read data from it. When I open session and scan tags, stream function does not fire and I can't understand what I'm doing wrong.

import Foundation
import ExternalAccessory


class RFID: NSObject, EAAccessoryDelegate, StreamDelegate {

        var _accessory: EAAccessory!
        var _session: EASession!
        var _protocolString: String?


    func turnOn() {
        let manager = EAAccessoryManager.shared()
        let accessories = manager.connectedAccessories
        if (accessories.count > 0) {
            _accessory = accessories[0];

            _session = EASession(accessory: _accessory, forProtocol: _accessory.protocolStrings[0]);

            _accessory.delegate = self;
            _session?.inputStream?.delegate = self;
            _session?.inputStream?.schedule(in: .current, forMode: .default);
            _session?.inputStream?.open();

            print(_accessory);
            print(_session);
        }
    }

    func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
        switch eventCode {
        case Stream.Event.openCompleted:
            break
        case Stream.Event.hasBytesAvailable:
            // Read Data
            print("Data Available");
            break
        case Stream.Event.hasSpaceAvailable:
            // Write Data
            break
        case Stream.Event.errorOccurred:
            break
        case Stream.Event.endEncountered:
            break

        default:
            break
        }
    }
}

NOTE: printed accessory is always right one!

来源:https://stackoverflow.com/questions/56988131/easession-stream-function-doesnt-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!