‘UIPopoverPresentationController should have a non-nil sourceView or barButtonItem set before the presentation occurs.’
Bug场景 :ios 开发,iPad调用分享,Alert等系统弹板崩溃闪退,iPhone正常
大致是iPad Present的时候,需要挂到某个view上
解决方案:Present之前添加以下代码
//alert 是你的UIAlertController UIActivityViewController等
let isPad = ( UIDevice.current.userInterfaceIdiom == .pad)
if isPad {
alert.popoverPresentationController?.sourceView = self.view
alert.popoverPresentationController?.sourceRect = CGRect(x: 0, y:Int(UIScreen.main.bounds.size.height), width: Int(UIScreen.main.bounds.size.width), height: 30)
alert.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.any
}