從 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)
}
}
uj5u.com熱心網友回復:
我們的一個應用程式在生產中產生了完全相同的崩潰,我們已經為崩潰制定了解決方法。
您可以創建一個擴展UIActivityViewController的CustomShareSheet類,當應用程式退出其活動狀態時,此類將關閉 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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/491087.html
標籤:IOS 迅速 苹果手机 ios-sharesheet IOS-15.4
