I'm using a PDF Viewer on my app with PDFKit, and can present a modal view this way:
.sheet(isPresented: $showingPDF) {
let url = Bundle.main.url(forResource: "Sylvia", withExtension: "pdf")
CustomPDFView(displayedPDFURL: url!)
Being this my PDFViewer:
import SwiftUI
import PDFKit
struct CustomPDFView: View {
let displayedPDFURL: URL
var body: some View {
PDFKitRepresentedView(documentURL: displayedPDFURL)
}
}
struct PDFKitRepresentedView: UIViewRepresentable {
let documentURL: URL
init(documentURL: URL) {
self.documentURL = documentURL
}
func makeUIView(context: Context) -> some UIView {
let pdfView = PDFView()
pdfView.document = PDFDocument(url: self.documentURL)
pdfView.autoScales = true
pdfView.displayMode = .singlePage
pdfView.usePageViewController(true)
pdfView.displayDirection = .horizontal
return pdfView
}
func updateUIView(_ uiView: UIViewType, context: Context) -> Void {
}
}
It works perfectly for local PDF files, but: how can I make use of iCloud sharing links? I can open links of this kind (https://www.icloud.com/iclouddrive/...) on my work.link property, this way, perfectly:
Link("Open", destination: URL(string: work.link!)!)
...but only on preview app itself, not on my PDFViewer. Is it possible to open this kind of links in my own viewer?