I have an iPhone application that I am trying to make universal. I have this code:
let documentMenu = UIDocumentMenuViewController(documentTypes: [kUTTypeContent as String], inMode: .Import)
documentMenu.modalPresentationStyle = .FormSheet
documentMenu.delegate = self
self.presentationContext.presentViewController(documentMenu, animated: true, completion: nil)
self.presentationContext is just a view controller passed into the class.
Every time this code is executed, this error occurs:
Your application has presented a UIDocumentMenuViewController (). In its current trait environment, the modalPresentationStyle of a UIDocumentMenuViewController with this style is UIModalPresentationPopover. You must provide location information for this popover through the view controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the view controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.
I am not sure what's going on. I have even tried to set the sourceView and sourceRect, to which does stop the error, however, it sticks the DocumentMenuViewController into a popover, I do not what that. I need this modally presented in the center of the screen. Any help is appreciated.
Following code is working fine
let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)
importMenu.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With