I was adding a feature to a Rork Max app that just uses a few user-picked photos for a collage. Photos chosen through PHPickerViewController displayed fine on the spot and edits worked. But relaunch the app, and the photos I'd just picked came back black or failed to load. Pick them again and it's fixed, but the state I thought I'd saved was broken — that's the shape of the reports. Nothing that looks like an error appears.
The cause was holding onto the temporary reference PHPicker returns, thinking "I'll just read it later." On today's iOS, where limited access is the norm, you have to design on the assumption that a URL or PHAsset identifier valid at selection time won't be readable next time. As an indie developer who's worked on photo apps for a long time, I've learned that missing this "valid only at the moment of selection" nature of limited access means data quietly goes missing in production. This walks through adding photo import to a Rork Max native app with the smallest diff: how to avoid the holding-on trap, and an import layer you can use as-is.
What PHPicker hands you instead of "not asking for permission"
The big advantage of PHPickerViewController is that it works without the photo-library permission dialog. Only the photos the user selects inside the system UI reach the app, so the app holds no access to the whole library. That's the decisive difference from the older UIImagePickerController.
What arrives is a spout, not the bytes
The NSItemProvider PHPicker returns isn't the photo itself — it's "a spout you can draw from right now." You can read it on the spot with loadFileRepresentation or loadDataRepresentation, but the temporary file URL you get back expires after the callback returns. Think "I'll save the URL and open it later" and you drop into an unreadable state on next launch.
A PHAsset identifier is no guarantee of persistence either
You can configure preferredAssetRepresentationMode on PHPickerConfiguration to reach a PHAsset, but under limited access there's no guarantee the asset the app could see then will be visible next time. If the user later changes their selection, the identifier remains but you can no longer resolve it to the bytes. Running photo apps, I've moved away from any design that leans on persisting asset identifiers.
The core of the fix: copy the bytes the moment they're picked
Stop trying to hold on. Inside the selection callback, copy the bytes fully into your own persistent area (like Application Support). Reference only that local file afterward. This is the straightforward design for the limited-access era. Pay the cost once at import, then treat it as your own file — and URL expiry and selection changes become irrelevant.
import PhotosUI
import UniformTypeIdentifiers
import os
let picLog = Logger(subsystem: "net.rorklab.sample", category: "photo")
enum PhotoImportError: Error { case noImageRep, copyFailed }
final class PhotoImporter {
private let dir: URL = {
let base = FileManager.default.urls(for: .applicationSupportDirectory,
in: .userDomainMask)[0]
let d = base.appendingPathComponent("imported", isDirectory: true)
try? FileManager.default.createDirectory(at: d, withIntermediateDirectories: true)
return d
}()
// Take PHPicker results, return an array of persistent paths
func importItems(_ results: [PHPickerResult]) async -> [URL] {
var saved: [URL] = []
for result in results {
do {
let url = try await copyToLocal(result.itemProvider)
saved.append(url)
picLog.info("imported: \(url.lastPathComponent)")
} catch {
picLog.error("import failed: \(error.localizedDescription)")
}
}
return saved
}
}