Contents

webView(_:decidePolicyFor:decisionHandler:)

Asks the delegate for permission to navigate to new content after the response to the navigation request is known.

Declaration

optional func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping @MainActor @Sendable (WKNavigationResponsePolicy) -> Void)
optional func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse) async -> WKNavigationResponsePolicy

Parameters

  • webView:

    The web view from which the navigation request began.

  • navigationResponse:

    Descriptive information about the navigation response.

  • decisionHandler:

    A completion handler block to call with the results about whether to allow or cancel the navigation. This handler has no return value and takes the following parameter:

    policy

    A constant that indicates whether to cancel or allow the navigation. For a list of possible values, see Wknavigationresponsepolicy.

Mentioned in

Discussion

Use this method to allow or deny a navigation request after the web view receives the response to its original URL request. The navigationResponse parameter contains the details of the response, including the type of data that the response contains. If you implement this method, always execute the decisionHandler block at some point. You may execute it synchronously from your delegate method’s implementation, or execute it asynchronously after your method returns.

See Also

Allowing or denying navigation requests