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 -> WINetworkSharingAskToShareStateParameters
- 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
nilwhen your accessory provides no scan information. The closure receives:accessory: The
ASAccessoryconfigured for this provider.scanRequest: An
AccessoryScanRequestcontaining scan parameters.Returns: An
AccessoryScanResponsewith accessory scan results, ornilwhen 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
newShareableNetworkAvailabletotruewhen 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.