iOS 15.4.0 ShareSheet _activityImage 不支持进程外活动的代理
iOS 15.4.0 ShareSheet _activityImage is not supported for proxies to out-of-process activities
从 iOS 15.4.0 开始,我们在 Crashlytics 上发生了崩溃,但不知道如何重现和修复它。由于 Apple 默认的 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)
}
}
我们的一个应用程序在生产中产生了完全相同的崩溃,我们已经为崩溃制定了解决方法。
您可以创建一个扩展 UIActivityViewController 的 CustomShareSheet class,并且此 class 将关闭 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)
从 iOS 15.4.0 开始,我们在 Crashlytics 上发生了崩溃,但不知道如何重现和修复它。由于 Apple 默认的 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)
}
}
我们的一个应用程序在生产中产生了完全相同的崩溃,我们已经为崩溃制定了解决方法。
您可以创建一个扩展 UIActivityViewController 的 CustomShareSheet class,并且此 class 将关闭 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)