EASession流功能不会触发

时间:2019-07-11 11:26:53

标签: swift external-accessory mfi

我有MFi设备(RFID阅读器),并且正在尝试在我的应用程序中捕获扫描的标签。因此,我使用EAAccessorymanager来获取共享附件并从中读取数据。当我打开会话并扫描标签时, stream 函数不会触发,并且我无法理解我在做什么错。

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
        }
    }
}

注意:打印附件总是正确的!

0 个答案:

没有答案