BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

[SwiftUI] Does not render PDF after app closes

Forums > SwiftUI

I'm building an app that renders PDFs in SwiftUI through PDFKit.

Users can choose the PDF which they want to render. It's done through .fileImporter which returns a URL.

The URL works fine and I can render the PDF using the provided URL (I have to call url.startAccessingSecurityScopedResource() in order to render it; without calling that method, it does not render).

The trick is when I close the app, open it, and try to render a PDF using the URL that I obtained in a previous session, it just does not work, it renders empty string. I have to re-upload the file again (it generates absolutely the same URL) in order to make it render correctly.

What am I missing? I'm asking this question because unfortunately XCode does not give any any errors/warnings and I literally have no idea what to dig at least.

   

Not sure if its your problem, but I had problems with a Mac app. I could display a file selection dialog and the user could select a file and I could read it fine. If I stored the url and tried to open the file next time my app ran, I could not read the file. I didn't crash, just got nothing back. To make this work, I had to turn off sandboxing for the app. The sandboxing restrictions would only let me open files selected by the user directly. Any url I tried to access that was not selected by the user would fail.

Never found a way round it, so just deleted the Sandbox options from my app and run without sandboxing.

Steve

   

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

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.