RxExternalAccessory 2.0.0

RxExternalAccessory 2.0.0

Maintained by Kamil Harasimowicz.



  • By
  • Kamil Harasimowicz

RxExternalAccessory

Swift Version License Platform

RxSwift wrapper around ExternalAccessory framework

Instalation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate RxExternalAccessory into your Xcode project using CocoaPods, specify it in your Podfile:

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

pod 'RxExternalAccessory'

Then, run the following command:

$ pod install

Usage

Create RxEAAccessoryManager instance:

let rx_manager = RxEAAccessoryManager()

Available actions:

// 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()

You can observe:

// 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)

Contributing

Bug reports and pull requests are welcome.

License

RxExternalAccessory is released under the MIT license. See LICENSE for details.