Swiftpack.co - pawelrup/RxDocumentPicker as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by pawelrup.
pawelrup/RxDocumentPicker 0.2.0
Reactive extension for UIDocumentMenuViewController and UIDocumentPickerViewController.
⭐️ 9
🕓 3 years ago
iOS
.package(url: "https://github.com/pawelrup/RxDocumentPicker.git", from: "0.2.0")

RxDocumentPicker

CI Status Version License Platform Xcode Swift 5.3

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.

GitHub

link
Stars: 9
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

3 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics