UIDocumentPickerViewController import SSL Certificate

171 Views Asked by At

How can I import a SSL Certificate using UIDocumentPickerViewController?

I'm doing something like this:

let documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(documentTypes: ["public.item"], in: UIDocumentPickerMode.import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet

if #available(iOS 11.0, *) {
    documentPicker.allowsMultipleSelection = false
}

UINavigationBar.appearance().tintColor = .green
self.present(documentPicker, animated: true, completion: completion)

But the .cer file is always disable to select it:

cer disabled

Also, I can't find a way to import files without extension.

1

There are 1 best solutions below

0
On BEST ANSWER

This is how I make it works. First, I had to import mobile core services:

import MobileCoreServices

Then, this is how I instantiate the UIDocumentPickerViewController:

let types: NSArray = NSArray(object: kUTTypeX509Certificate as NSString)
let documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(documentTypes: types as! [String], in: UIDocumentPickerMode.import)

By the way, I only make it works with iCloud Drive, it doesn't work with Google Drive apparently by a bug: http://www.openradar.me/24187873