Reputation: 528
let langs = try? VNRecognizeTextRequest.supportedRecognitionLanguages(for: .fast, revision: 2)
let alertController = UIAlertController(title: "Select Language".localized, message: nil, preferredStyle: .actionSheet)
for lang in langs ?? []{
let title = GlobalFunctions.getLanguageNameFrom(code: lang)
let action = UIAlertAction(title: title, style: .default) { action in
completion?(lang)
}
alertController.addAction(action)
}
let actionCancel = UIAlertAction(title: "Cancel".localized, style: .cancel, handler: nil)
alertController.addAction(actionCancel)
AppDelegate.shared.window?.rootViewController?.present(alertController, animated: true, completion: nil)
I received this error:
Thread 1: "Your application has presented a UIAlertController (<UIAlertController: >) of style UIAlertControllerStyleActionSheet from UISplitViewController (<UISplitViewController: >). The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation."
I know I should add some code like this but its global function class I don't have a view
popoverPresentationController.sourceView = self.view
popoverPresentationController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
Upvotes: 0
Views: 55