RxSwift wrapper around ExternalAccessory framework
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
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)
Bug reports and pull requests are welcome.
RxExternalAccessory is released under the MIT license. See LICENSE for details.