UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

iCloud Drive PDFs opening

Forums > SwiftUI

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?

1      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.