RxExternalAccessory 2.0.0

RxExternalAccessory 2.0.0

Kamil Harasimowicz维护。



  • 作者:
  • Kamil Harasimowicz

RxExternalAccessory

Swift Version License Platform

RxSwift围绕ExternalAccessory框架的封装

安装

CocoaPods

CocoaPods是Cocoa项目的依赖项管理器。您可以以下命令安装它

$ gem install cocoapods

为了使用CocoaPods将RxExternalAccessory集成到你的Xcode项目中,请在你的Podfile指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

pod 'RxExternalAccessory'

然后,运行以下命令

$ pod install

使用

创建RxEAAccessoryManager实例

let rx_manager = RxEAAccessoryManager()

可用动作

// tries to open session with first match from available accessories for given `supportedProtocols`
rx_manager.tryConnectingAndStartCommunicating(forProtocols: supportedProtocols)

// tries to open session for given `EAAccessory`
rx_manager.tryConnectingAndStartCommunicating(to: accessory, forProtocols: supportedProtocols)

// stops any working sessions
rx_manager.stopCommunicating()

你可以观察

// available accessories - Observable<[EAAccessory]>
rx_manager.connectedAccessories
    .subscribe(onNext: { accessories in
        // DO SOMETHING
    })
    .disposed(by: disposeBag)

// current opened session (nil if any session on) - Observable<EASession?>
rx_manager.session
    .subscribe(onNext: { session in
        // DO SOMETHING
    })
    .disposed(by: disposeBag)

// calls from `StreamDelegate` - Observable<StreamResult> where StreamResult = (aStream: Stream, eventCode: Stream.Event)
rx_manager.streamResult
    .subscribe(onNext: { stream, eventCode in
        switch (stream, eventCode) {
        case (let inputStream as InputStream, .hasBytesAvailable):
            // DO SOMETHING
            break
        default:
            break
        }
    })
    .disposed(by: disposeBag)

贡献

欢迎提交bug报告和pull请求。

许可证

RxExternalAccessory以MIT许可证发布。请参阅LICENSE文件以获取详细信息。