Reputation: 289
I am trying to initiate DocumentPicker in my app. I have declared:
var documentPicker: UIDocumentPickerViewController =
UIDocumentPickerViewController(documentTypes:
["public.text"], in: UIDocumentPickerMode.open)
documentPicker.delegate = self
documentPicker.modalPresentationStyle =
UIModalPresentationStyle.fullScreen
self.present(documentPicker, animated: true, completion: nil)
}
and for picked document:
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {
if controller.documentPickerMode == UIDocumentPickerMode.exportToService {
//do some stuff
}
dismiss(animated: true, completion: nil)
}
However i am doing something wrong here. Whenever i choose a file or close the window I keep getting this error:
viewServiceDidTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}.
I have tried looking for a solution but i couldn't find anything useful.
EDIT: I have included a couple of print("test") into the documentPicker function to see if it is working. However i get 0 response from the console. Maybe I have implemented documentPicker in a bad way?
Upvotes: 5
Views: 6830
Reputation: 179
I, too, get this error message but not all the time.
I noticed the documentPicker is deprecated. Try this:
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL urls: [URL]) {
if controller.documentPickerMode == UIDocumentPickerMode.exportToService {
//do some stuff
}
}
There's no need to have the dismiss statement. The picker is closed automatically.
Try this and see if it works.
Upvotes: 2