GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

[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

   

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.

Click to save your free spot now

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

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.