IOS 8 iPad App Crashes When UIActivityViewController Is Called

前端 未结 5 466
借酒劲吻你
借酒劲吻你 2020-12-19 04:08

When a UIActivityViewController is called on the iPhone in this app, it works perfectly, but when called on a iPad, the app crashes. Below is the code I used:



        
5条回答
  •  醉酒成梦
    2020-12-19 04:42

    There are two option, the action came from a UIBarButtonitem or UIButton that is a UIView.

    func shareButtonPress() {
    
        ...
    
        if let actv = activityViewController.popoverPresentationController {
            actv.barButtonItem = someBarButton // if it is a UIBarButtonItem
    
            // Or if it is a view you can get the view rect
            actv.sourceView = someView
            // actv.sourceRect = someView.frame // you can also specify the CGRect
        }
    
        self.presentViewController(activityViewController, animated: true, completion: nil)
    }
    

    You may have to add a sender to your function like func shareButtonPress(sender: UIBarButtonItem) or func shareButtonPress(sender: UIButton)

提交回复
热议问题