iOS 15.4.0 ShareSheet _activityImage不支持代理进程外活动



从iOS 15.4.0开始,我们在Crashlytics上有崩溃,但不知道如何复制和修复它。由于苹果默认的shareSheet,它正在产生崩溃。我希望有人能提供一些见解来解决这个问题。

打开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)
}
}

我们的一个应用程序在生产中产生了完全相同的崩溃,我们已经为崩溃做了一个解决方案。

可以创建一个CustomShareSheet类扩展了UIActivityViewController当应用程序退出活动状态时,这个类会解散CustomShareSheetController,这样崩溃就不会再发生了。

class CustomShareSheet: UIActivityViewController {

override func viewDidLoad() {
debugPrint("CustomShareSheet (#function)")
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillResignActive(notification:)), name: UIApplication.willResignActiveNotification, object: nil)
}

@objc private func applicationWillResignActive(notification: NSNotification) {
self.dismiss(animated: true)
debugPrint("(#function) || dismissed")
}
}

===========================

class Helper {
class func shareFiles(rootVC: UIViewController, items: [Any]) {
debugPrint("(#function) || itemCount: (items.count)")
let customShareSheet = CustomShareSheet(activityItems: items, applicationActivities: nil) // Uses of CustomShareSheet
// This lines is for the popover you need to show in iPad
customShareSheet.popoverPresentationController?.sourceView = rootVC.view
// This line remove the arrow of the popover to show in iPad
customShareSheet.popoverPresentationController?.permittedArrowDirections = .down
customShareSheet.popoverPresentationController?.sourceRect = CGRect(x: UIScreen.main.bounds.width/2,
            y: UIScreen.main.bounds.height,
            width: 0, height: 0)
DispatchQueue.main.async {
rootVC.present(customShareSheet, animated: true, completion: nil)
}
}
}

===========================

var _items = [Any]()
Helper.shareFiles(rootVC: yourCurrentViewController, items: _items)