Monday, October 16, 2017

Google drive not behaving to provided UTI from UIDocumentPickerViewController in iOS app

Leave a Comment

I am building an iOS app which uses UIDocumentPickerViewController to open iCloud drive and Google drive. I have provided allowed UTI as 'com.adobe.pdf' as I only need PDF files access. The UTI is working fine in iCloud Drive but google drive provide me access of google sheet files also. Whereas excel files are behaving properly. How can I restrict drive to PDF files only?

1 Answers

Answers 1

I achieved this using this code :

let docActionButton: UIAlertAction = UIAlertAction(title: "Document", style: .Default)     { action -> Void in         var documentMediaTypes: [String] = []         documentMediaTypes.append(String(kUTTypePDF))            let viewController: UIDocumentMenuViewController = UIDocumentMenuViewController(documentTypes: documentMediaTypes, inMode: .Import)          viewController.delegate = self         viewController.modalPresentationStyle = .FormSheet           self.presentViewController(viewController, animated: true, completion: { _ in })       } 

And then check at successful selection of a file

 func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {     print(url.path)     if (url.path!.componentsSeparatedByString("/").last!).componentsSeparatedByString(".").last! == "pdf" { } } 

This code

var documentMediaTypes: [String] = []     documentMediaTypes.append(String(kUTTypePDF)) 

makes sure only pdf files are show for picking.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment