Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sharing crash iOS 16 #127

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions Sources/Addons/Sharing/Activity/SharingActivityManager.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
#if canImport(UIKit) && os(iOS)
import UIKit

@MainActor
internal final class SharingActivityManager<Activity: SharingCustomActivity>: UIActivity, Sendable {
internal final class SharingActivityManager<Activity: SharingCustomActivity>: UIActivity, @unchecked Sendable {

internal override class var activityCategory: UIActivity.Category {
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

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? {
Expand All @@ -55,16 +66,12 @@ internal final class SharingActivityManager<Activity: SharingCustomActivity>: 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() {
Expand Down
Loading