I have the following code - you can see where I had to comment out the code on the simulator. Is this expected? The code works perfectly fine on a physical iPad device. Is it documented somewhere that NSFileVersion doesn't work with non-local versions in the simulator?
func loadPreviewDirectly(
from version: NSFileVersion,
completion: @escaping (CIImage?) -> Void
) {
let versionURL = version.url
let access = versionURL.startAccessingSecurityScopedResource()
defer { if access { versionURL.stopAccessingSecurityScopedResource() } }
print("Loading version: \(version.persistentIdentifier) | Local: \(version.hasLocalContents)")
// 1. SIMULATOR CATCH: If running in simulator and the file is missing, it will never download.
#if targetEnvironment(simulator)
if !version.hasLocalContents {
print("⚠️ iOS Simulator cannot materialize remote NSFileVersions. Fallback triggered.")
// You cannot test remote versions here. For testing on the simulator,
// test with a version where version.hasLocalContents == true (created locally in this session).
DispatchQueue.main.async { completion(nil) }
return
}
#endif
let coordinator = NSFileCoordinator()
var coordinationError: NSError?
// 2. Wrap everything in a sequential reading coordination
coordinator.coordinate(readingItemAt: versionURL, options: [], error: &coordinationError) { readURL in
let image = CIImage(contentsOf: readURL)
DispatchQueue.main.async {
completion(image)
}
}
if let error = coordinationError {
DispatchQueue.main.async {
self.errorMessage = error.localizedDescription
completion(nil)
}
}
}
I have the following code - you can see where I had to comment out the code on the simulator. Is this expected?
I haven't looked closely at the specific details, but the short answer is that, yes, it's almost certainly expected. Architecturally, the simulator is basically a "port" of iOS to macOS, not a fully functional OS that's running independently. This works fine for its primary function (basic UI development and basic functional testing), but it creates a problem with lower-level systems where the feature overlaps with existing macOS functionality and/or would require implementing parts of iOS that were otherwise not implemented. In most of those cases, the simulator tends to simply avoid the entire issue by not implementing the functionality at all.
The code works perfectly fine on a physical iPad device. Is it documented somewhere that NSFileVersion doesn't work with non-local versions in the simulator?
No, probably not. The simulator has always been considered a development aid, so these details have never been documented to the same extent as the broader system.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware