IOS 8 iPad App Crashes When UIActivityViewController Is Called

前端 未结 5 437
借酒劲吻你
借酒劲吻你 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:47

    Swift 5:

    Check if the device is iPhone or iPad and based on that add a sourceView and present the activityController

    let activity = UIActivityViewController(activityItems: [self], applicationActivities: nil)
    if UIDevice.current.userInterfaceIdiom == .phone {
        UIApplication.topViewController?.present(activity, animated: true, completion: nil)
    } else {
        activity.popoverPresentationController?.sourceView = UIApplication.topViewController!.view
        UIApplication.topViewController?.present(activity, animated: true, completion: nil)
    }
    

提交回复
热议问题