Contents

fetchLatestRemoteVersionOfItem(at:completionHandler:)

Asynchronously fetches the latest remote version of a given item from the server.

Declaration

func fetchLatestRemoteVersionOfItem(at url: URL, completionHandler: @escaping  @Sendable (NSFileVersion?, (any Error)?) -> Void)
func fetchLatestRemoteVersionOfItem(at url: URL) async throws -> NSFileVersion

Parameters

  • url:

    The URL of the item for which to check the version.

  • completionHandler:

    A closure or block that the framework calls when the fetch action completes. It receives parameters of types Nsfileversion and Nserror. The error is nil if fetching the remote version succeeded; otherwise it indicates the error that caused the call to fail. In Swift, you can omit the completion handler, catching any error in a do-catch block and receiving the version as the return value.

Discussion

Use this method if uploading fails due to a version conflict and sync is paused. In this case, fetching the latest remote version allows you to inspect the newer item from the server, resolve the conflict, and resume uploading.

The version provided by this call depends on several factors:

  • If there is no newer version of the file on the server, the caller receives the current version of the file.

  • If the server has a newer version and sync isn’t paused, this call replaces the local item and provides the version of the new item.

  • If the server has a newer version but sync is paused, the returned version points to a side location. In this case, call replaceItem(at:options:) on the provided version object to replace the local item with the newer item from the server.

If the device isn’t connected to the network, the call may fail with NSFileReadUnknownError, with the underlying error of serverUnreachable.

See Also

Controlling file provider synchronization