Contents

uploadLocalVersionOfUbiquitousItem(at:withConflictResolutionPolicy:completionHandler:)

Asynchronously uploads the local version of the item using the provided conflict resolution policy.

Declaration

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

Parameters

  • url:

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

  • conflictResolutionPolicy:

    The policy the file manager applies if the local and server versions conflict.

  • completionHandler:

    A closure or block that the framework calls when the upload 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

Once your app pauses a sync for an item, call this method every time your document is in a stable state. This action keeps the server version as up-to-date as possible.

If the server has a newer version than the one to which the app made changes, uploading fails with NSFileWriteUnknownError, with an underlying error of localVersionConflictingWithServer. In this case, call fetchLatestRemoteVersionOfItem(at:completionHandler:), rebase local changes on top of that version, and retry the upload.

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

See Also

Controlling file provider synchronization