From iOS 15.4.0 we have the crash on Crashlytics but don't known how to reproduce and fix it. It is producing crash due to Apple default shareSheet. I hope someone can provide some insights to fix this.
Code I use to open shareSheet
func shareFiles(rootVC: UIViewController, items: [Any]) {
let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
// This lines is for the popover you need to show in iPad
activityViewController.popoverPresentationController?.sourceView = rootVC.view
// This line remove the arrow of the popover to show in iPad
activityViewController.popoverPresentationController?.permittedArrowDirections = .down
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: UIScreen.main.bounds.width/2,
y: UIScreen.main.bounds.height,
width: 0, height: 0)
DispatchQueue.main.async {
rootVC.present(activityViewController, animated: true, completion: nil)
}
}
One of our applications was producing the exact same crash on production and We've made a workaround for the crash.
You can create a CustomShareSheet class that extends UIActivityViewController and this class will dismiss the CustomShareSheetController when the application will resign from its active state, thus the crash won't occur anymore.
===========================
===========================