RxDocumentPicker
Requirements
Xcode 12, Swift 5.3
Installation
Swift Package Manager
RxUserNotifications is available through Swift Package Manager. To install it, add the following line to your Package.swift into dependencies:
.package(url: "https://github.com/pawelrup/RxDocumentPicker", .upToNextMinor(from: "0.2.0"))and then add RxUserNotifications to your target dependencies.
CocoaPods
RxDocumentPicker is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'RxDocumentPicker'Usage
For iOS versions before iOS 11 you can use UIDocumentMenuViewController like below:
let menu = UIDocumentMenuViewController(documentTypes: [kUTTypePDF as String], in: .import)
menu.rx
.didPickDocumentPicker
.do(onNext: { [weak self] (picker: UIDocumentPickerViewController) in
self?.present(picker, animated: true, completion: nil)
})
.flatMap { $0.rx.didPickDocumentAt }
.subscribe(onNext: {
print($0)
})
.disposed(by: disposeBag)
present(menu, animated: true, completion: nil)UIDocumentMenuViewController is deprecated from iOS 11 so you need to use UIDocumentPickerViewController directly:
let picker = UIDocumentPickerViewController(documentTypes: [kUTTypePDF as String], in: .import)
picker.rx
.didPickDocumentsAt
.subscribe(onNext: { [weak self] (urls: [URL]) in
print(urls)
})
.disposed(by: disposeBag)
present(picker, animated: true, completion: nil)If you want to know when user cancelled picking documents you can subscribe to documentPickerWasCancelled like below:
let picker = UIDocumentPickerViewController(documentTypes: [kUTTypePDF as String], in: .import)
picker.rx
.documentPickerWasCancelled
.subscribe(onNext: {
// Do something
})
.disposed(by: disposeBag)
present(picker, animated: true, completion: nil)You can see usage of RxDocumentPicker in example.
Author
Paweł Rup, [email protected]
License
RxDocumentPicker is available under the MIT license. See the LICENSE file for more info.