Contents

setDefaultApplication(at:toOpenFileAt:completion:)

Sets the default app to use when opening a specific file.

Declaration

func setDefaultApplication(at applicationURL: URL, toOpenFileAt url: URL, completion completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)
func setDefaultApplication(at applicationURL: URL, toOpenFileAt url: URL) async throws

Parameters

  • applicationURL:

    The URL of the default app to use when opening the file.

  • url:

    The URL of the file to open.

  • completionHandler:

    The completion handler to call after the operation completes.

Discussion

This method sets the default app to use for a specific file (rather than all files of that content type). The system requires write access to the specified url before it can make the change.

If a change requires user consent, the system asks the user for consent asynchronously before invoking the completion handler.

This function doesn’t apply to non-file URLs.

See Also

Setting Default Application Information