Last active
September 24, 2016 07:01
-
-
Save hemant3370/3168c46544a34db31cdc47a5ded250f0 to your computer and use it in GitHub Desktop.
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
// Showing the menu action sheet | |
var documentMediaTypes: [String] = [] | |
documentMediaTypes.append(String(kUTTypePDF)) | |
documentMediaTypes.append(String(kUTTypePNG)) | |
documentMediaTypes.append(String(kUTTypeImage)) | |
documentMediaTypes.append(String(kUTTypeVideo)) | |
documentMediaTypes.append(String(kUTTypeMovie)) | |
documentMediaTypes.append(String(kUTTypeItem)) | |
let viewController: UIDocumentMenuViewController = UIDocumentMenuViewController(documentTypes: documentMediaTypes, inMode: .Import) | |
viewController.delegate = self | |
viewController.modalPresentationStyle = .FormSheet | |
self.presentViewController(viewController, animated: true, completion: { _ in }) | |
// Menu picker Delegate | |
func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) { | |
documentPicker.delegate = self | |
self.presentViewController(documentPicker, animated: true, completion: nil) | |
} | |
// File Picked delegate | |
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) { | |
print(url.path) | |
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first! | |
let docURL = documentsUrl.URLByAppendingPathComponent(url.path!.componentsSeparatedByString("/").last!) | |
do { | |
let docData = try NSData(contentsOfURL: url, options: NSDataReadingOptions()) | |
docData.writeToURL(docURL, atomically: true) | |
} catch { | |
print(error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment