I am trying to use ShareLink to share a multi-page PDF that I've created and also stored locally as a .pdf file. The extension that I'm using to make the PDF transferable is as follows:
extension PDFDocument: Transferable {
public static var transferRepresentation: some TransferRepresentation {
DataRepresentation(exportedContentType: .pdf) { pdf in
return pdf.dataRepresentation() ?? Data()
}
}
}
This seems to work for items like Messages, Mail, AirDrop, and Save to Files in the share sheet that's presented. It does NOT work for Print (nothing happens when clicked and the share sheet is just dismissed). However, it does work for Print with HP Smart (I have an HP printer in addition to a laser printer). My questions are as follows:
Is DataRepresentation the correct TransferRepresentation to use for PDFs or should I be using FileRepresentation or ProxyRepresentation?
Is there a way to limit/customize the automatic share sheet that pops up so that "other options" like Markup, Twitter, Facebook, etc. are not shown?
If DataRepresentation is the correct TransferRepresentation to use for PDFs, am I missing something? I've seen others include multiple DataRepresentation statements (see below) in their code but I'm not sure what it's really doing because my results don't seem any different.
public static var transferRepresentation: some TransferRepresentation {
DataRepresentation(contentType: .pdf) { pdf in
pdf.dataRepresentation() ?? Data()
} importing: { data in
if let pdf = PDFDocument(data: data) {
return pdf
} else {
return PDFDocument()
}
}
DataRepresentation(exportedContentType: .pdf) { pdf in
return pdf.dataRepresentation() ?? Data() }
}
}
Any help/advice would be greatly appreciated! Thanks!