Created
November 5, 2019 11:42
-
-
Save Ilesh/d292ae0ae71b624eacbda5e937b1f11e to your computer and use it in GitHub Desktop.
iCloud UIDocumentPickerDelegate with specific files like doc, documents, text and PDF.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// IPDocumentPicker.swift | |
// | |
// | |
// Created by Ilesh on 22/11/18. | |
// Copyright © 2018. All rights reserved. | |
// | |
import UIKit | |
import MobileCoreServices | |
class IPDocumentPicker :NSObject,UIDocumentPickerDelegate { | |
static let shared = IPDocumentPicker() | |
typealias complitionHandler = (Bool,URL?) -> Swift.Void | |
private var block : complitionHandler? | |
func OpenDocumentpicker(controller:UIViewController, response: @escaping complitionHandler){ | |
let types = [kUTTypePDF,"com.microsoft.word.doc","org.openxmlformats.wordprocessingml.document",] as [Any] | |
let documentPicker = UIDocumentPickerViewController(documentTypes: types as! [String], in: .import) | |
documentPicker.delegate = self | |
block = response | |
documentPicker.modalPresentationStyle = .formSheet | |
UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self]).tintColor = UIColor.black | |
controller.present(documentPicker, animated: true, completion: nil) | |
} | |
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { | |
print("IPDocumentPicker :- Cancelled ") | |
self.block?(true,nil) // isCancel,nil | |
} | |
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { | |
print("IPDocumentPicker URL:- \(urls)") | |
self.block?(false,urls.first) | |
} | |
} | |
/*extension IPDocumentPicker: UIDocumentPickerDelegate { | |
}*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment