Hi! I'm working on the app where users can share their content via collaboration or just send copy as a json file. The problem I'm facing is that I cannot make it work correctly in Messages. Having only one option like Collaboration or Send Copy work just fine but with active selector between those two options on share sheet is confuse me a lot.
I use ShareLink along with Transferable protocol
@ViewBuilder
private var control: some View {
if let presentation {
ShareLink(
item: shareItem(for: presentation),
preview: preview(for: presentation)
) {
label
}
} else {
Button {} label: { label }
.disabled(true)
}
}
public static var transferRepresentation: some TransferRepresentation {
CKShareTransferRepresentation { item in
return item.exportedShare(for: plan)
}
.exportingCondition { $0.collaborationPlan != nil }
FileRepresentation(exportedContentType: .customDocumentType) { item in
SentTransferredFile(item.copyFileURL)
}
}
private func exportedShare(
for plan: ShareCollaborationPlan
) -> CKShareTransferRepresentation<Self>.ExportedShare {
let container = CKContainer(identifier: plan.containerIdentifier)
let allowedSharingOptions = LiveCollaborationPermissionPolicy
.makeAllowedSharingOptions()
switch plan {
case let .existing(handle):
return .existing(
handle.shareForPresentation(title: title),
container: container,
allowedSharingOptions: allowedSharingOptions
)
case .prepare:
return .prepareShare(
container: container,
allowedSharingOptions: allowedSharingOptions
) { [prepareCollaboration] in
try await prepareCollaboration().shareForPresentation(title: title)
}
}
}
In general this works fine except Messages. When I trying to start Collaboration in Messages, it show an error "Collaboration Not Available" and it is trying to send a file instead of Collaboration link
I setup my CKShare like this
func shareForPresentation(title: String) -> CKShare {
share[CKShare.SystemFieldKey.title] = title
if let thumbnailImageData = Self.thumbnailImageData {
share[CKShare.SystemFieldKey.thumbnailImageData] = thumbnailImageData
}
return share
}
private static let thumbnailImageData: Data? = {
#if canImport(UIKit)
UIImage(named: "SharePreviewIcon", in: .main, compatibleWith: nil)?
.pngData()
#else
nil
#endif
}()
I have tried to use UIActivityController with NSItemProvider where I use registerCKShare and registerFileRepresentation on the same provider. It works also just fine, except Messages, where it always trying to send Collaboration no matter what I choose Collaboration or Send Copy on share sheet selector. I have tried to use two NSItemProvider's for CKShare and file, this works as I wanted but it messed-up metadata which is I'm not able to setup in the way I want. Please help me to understand how I can setup share where Collaboration and Send Copy work correctly with Messages?