UIActivityViewController in Swift Crashes on iPad

前端 未结 2 1429
我寻月下人不归
我寻月下人不归 2021-01-11 16:56

I am making a share function in my game and I have the code and it works fine on iPhone but when I test it on a iPad, when I tap the share button the app crashes. I am using

相关标签:
2条回答
  • 2021-01-11 17:08

    The popoverPresentationController sourceView needs to be set to current view.

    let activityVC = UIActivityViewController(activityItems: [quoteController.attributedString, view.screenShot()], applicationActivities: [])
        
    present(activityVC, animated: true)
    activityVC.popoverPresentationController?.sourceView = view
    
    
    0 讨论(0)
  • 2021-01-11 17:10

    The UIActivityViewController's has non-null popoverPresentationController property when running on iPad. So, try below.

    if let wPPC = activityVC.popoverPresentationController {
        wPPC.sourceView = some view
        //  or
        wPPC.barButtonItem = some bar button item
    }
    presentViewController( activityVC, animated: true, completion: nil )
    
    0 讨论(0)
提交回复
热议问题