NSFileVersion doesn't work in IOS simulator?

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)
            }
        }
    }
Answered by DTS Engineer in 894132022

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

Accepted Answer

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

Hmm, that's unfortunate - at a minimum you would think the list of things that are expected to be broken would be documented. Thank you for taking the time to respond.

NSFileVersion doesn't work in IOS simulator?
 
 
Q