From 996154b5279183aafa8bc1840589cb8d56edddfa Mon Sep 17 00:00:00 2001 From: Alexander Khodko Date: Sat, 19 Oct 2024 09:54:06 +0300 Subject: [PATCH 1/2] Fix Sharing crash iOS 16 --- .../Activity/SharingActivityManager.swift | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/Sources/Addons/Sharing/Activity/SharingActivityManager.swift b/Sources/Addons/Sharing/Activity/SharingActivityManager.swift index 7bc9dc4c..3ce1646b 100644 --- a/Sources/Addons/Sharing/Activity/SharingActivityManager.swift +++ b/Sources/Addons/Sharing/Activity/SharingActivityManager.swift @@ -1,8 +1,7 @@ #if canImport(UIKit) && os(iOS) import UIKit -@MainActor -internal final class SharingActivityManager: UIActivity, Sendable { +internal final class SharingActivityManager: UIActivity, @unchecked Sendable { internal override class var activityCategory: UIActivity.Category { Activity.category @@ -14,21 +13,15 @@ internal final class SharingActivityManager: UI internal let activity: Activity internal override var activityType: UIActivity.ActivityType? { - MainActor.assumeIsolated { - activity.type - } + activity.type } internal override var activityTitle: String? { - MainActor.assumeIsolated { - activity.title - } + activity.title } internal override var activityImage: UIImage? { - MainActor.assumeIsolated { - activity.image - } + activity.image } internal override var activityViewController: UIViewController? { @@ -55,16 +48,12 @@ internal final class SharingActivityManager: UI internal override func canPerform(withActivityItems activityItems: [Any]) -> Bool { let activityItems = activityItems.map(SharingItem.init(activityItem:)) - return MainActor.assumeIsolated { - activity.isApplicable(for: activityItems) - } + return activity.isApplicable(for: activityItems) } internal override func prepare(withActivityItems activityItems: [Any]) { let activityItems = activityItems.map(SharingItem.init(activityItem:)) - MainActor.assumeIsolated { - items = activityItems - } + items = activityItems } internal override func perform() { From 23d9e07e32ad11aa7be74d6c5b6f062092e4e603 Mon Sep 17 00:00:00 2001 From: Alexander Khodko Date: Sat, 19 Oct 2024 10:37:33 +0300 Subject: [PATCH 2/2] Added threadsafe --- .../Activity/SharingActivityManager.swift | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Sources/Addons/Sharing/Activity/SharingActivityManager.swift b/Sources/Addons/Sharing/Activity/SharingActivityManager.swift index 3ce1646b..a2b5c7ce 100644 --- a/Sources/Addons/Sharing/Activity/SharingActivityManager.swift +++ b/Sources/Addons/Sharing/Activity/SharingActivityManager.swift @@ -7,7 +7,25 @@ internal final class SharingActivityManager: UI Activity.category } - private var items: [SharingItem] = [] + private let accessQueue = DispatchQueue( + label: "SharingActivityManager \(UUID().uuidString)", + qos: .userInitiated, + attributes: .concurrent + ) + + private var _items: [SharingItem] = [] + private var items: [SharingItem] { + get { + accessQueue.sync { + _items + } + } + set { + accessQueue.async(flags: .barrier) { [weak self] in + self?._items = newValue + } + } + } internal let navigator: ScreenNavigator internal let activity: Activity