Contents

presentAskToShareUI(scanProvider:)

Presents system UI asking people to share available networks with an accessory.

Declaration

func presentAskToShareUI(scanProvider: (@Sendable (ASAccessory, WINetworkSharingProvider.AccessoryScanRequest) async -> WINetworkSharingProvider.AccessoryScanResponse?)? = nil) async throws -> WINetworkSharingAskToShareState

Parameters

  • scanProvider:

    The optional closure the system calls periodically to get updated scan results from the accessory. Returns networks your accessory discovers to help people select compatible, high-performance networks. Defaults to nil when your accessory provides no scan information. The closure receives:

    • accessory: The ASAccessory configured for this provider.

    • scanRequest: An AccessoryScanRequest containing scan parameters.

    • Returns: An AccessoryScanResponse with accessory scan results, or nil when no changes occurred since the previous results.

Return Value

The WINetworkSharingAskToShareState, indicating a response from the person.

Discussion

Call this method when your accessory needs additional networks or when the system indicates new shareable networks are available. The system checks for nearby known networks and prompts people to select networks to share with your accessory.

Your app extension can present sharing UI in these scenarios:

  • New networks available: The system sets newShareableNetworkAvailable to true when networks become available for sharing. Your extension can verify with your accessory whether it needs additional networks before calling this method. Your container app doesn’t need to be in the foreground for this scenario.

  • Accessory requests: Your accessory can communicate directly with your extension to request network sharing, such as when connection problems occur. Your container app needs to be in the foreground before calling this method.

  • App requests: Your container app can call askToShare() to set the appRequestedSharing flag, indicating it wants your extension to present sharing UI. Your container app needs to be in the foreground before calling this method.

See Also

Displaying network selection