Interface WKUIDelegate


  • public interface WKUIDelegate
    A class conforming to the WKUIDelegate protocol provides methods for presenting native UI on behalf of a webpage.
    • Method Detail

      • webViewCommitPreviewingViewController

        @Deprecated
        default void webViewCommitPreviewingViewController​(@NotNull
                                                           @NotNull WKWebView webView,
                                                           @NotNull
                                                           @NotNull UIViewController previewingViewController)
        Deprecated.
        Allows your app to pop to the view controller it created.
        Parameters:
        webView - The web view invoking the delegate method.
        previewingViewController - The view controller that is being popped. API-Since: 10.0 Deprecated-Since: 13.0
      • webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures

        @Nullable
        default @Nullable WKWebView webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures​(@NotNull
                                                                                                           @NotNull WKWebView webView,
                                                                                                           @NotNull
                                                                                                           @NotNull WKWebViewConfiguration configuration,
                                                                                                           @NotNull
                                                                                                           @NotNull WKNavigationAction navigationAction,
                                                                                                           @NotNull
                                                                                                           @NotNull WKWindowFeatures windowFeatures)
        Creates a new web view. The web view returned must be created with the specified configuration. WebKit will load the request in the returned web view. If you do not implement this method, the web view will cancel the navigation.
        Parameters:
        webView - The web view invoking the delegate method.
        configuration - The configuration to use when creating the new web view. This configuration is a copy of webView.configuration.
        navigationAction - The navigation action causing the new web view to be created.
        windowFeatures - Window features requested by the webpage.
        Returns:
        A new web view or nil.
      • webViewPreviewingViewControllerForElementDefaultActions

        @Nullable
        @Deprecated
        default @Nullable UIViewController webViewPreviewingViewControllerForElementDefaultActions​(@NotNull
                                                                                                   @NotNull WKWebView webView,
                                                                                                   @NotNull
                                                                                                   @NotNull WKPreviewElementInfo elementInfo,
                                                                                                   @NotNull
                                                                                                   @NotNull NSArray<?> previewActions)
        Deprecated.
        Allows your app to provide a custom view controller to show when the given element is peeked. Returning a view controller will result in that view controller being displayed as a peek preview. To use the defaultActions, your app is responsible for returning whichever of those actions it wants in your view controller's implementation of -previewActionItems. Returning nil will result in WebKit's default preview behavior. webView:commitPreviewingViewController: will only be invoked if a non-nil view controller was returned. API-Since: 10.0 Deprecated-Since: 13.0
        Parameters:
        webView - The web view invoking the delegate method.
        elementInfo - The elementInfo for the element the user is peeking.
        defaultActions - An array of the actions that WebKit would use as previewActionItems for this element by default. These actions would be used if allowsLinkPreview is YES but these delegate methods have not been implemented, or if this delegate method returns nil.
      • webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler

        default void webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler​(@NotNull
                                                                                                @NotNull WKWebView webView,
                                                                                                @NotNull
                                                                                                @NotNull java.lang.String message,
                                                                                                @NotNull
                                                                                                @NotNull WKFrameInfo frame,
                                                                                                @NotNull
                                                                                                @NotNull WKUIDelegate.Block_webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler completionHandler)
        Displays a JavaScript alert panel. For user security, your app should call attention to the fact that a specific website controls the content in this panel. A simple forumla for identifying the controlling website is frame.request.URL.host. The panel should have a single OK button. If you do not implement this method, the web view will behave as if the user selected the OK button.
        Parameters:
        webView - The web view invoking the delegate method.
        message - The message to display.
        frame - Information about the frame whose JavaScript initiated this call.
        completionHandler - The completion handler to call after the alert panel has been dismissed.
      • webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler

        default void webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler​(@NotNull
                                                                                                  @NotNull WKWebView webView,
                                                                                                  @NotNull
                                                                                                  @NotNull java.lang.String message,
                                                                                                  @NotNull
                                                                                                  @NotNull WKFrameInfo frame,
                                                                                                  @NotNull
                                                                                                  @NotNull WKUIDelegate.Block_webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler completionHandler)
        Displays a JavaScript confirm panel. For user security, your app should call attention to the fact that a specific website controls the content in this panel. A simple forumla for identifying the controlling website is frame.request.URL.host. The panel should have two buttons, such as OK and Cancel. If you do not implement this method, the web view will behave as if the user selected the Cancel button.
        Parameters:
        webView - The web view invoking the delegate method.
        message - The message to display.
        frame - Information about the frame whose JavaScript initiated this call.
        completionHandler - The completion handler to call after the confirm panel has been dismissed. Pass YES if the user chose OK, NO if the user chose Cancel.
      • webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler

        default void webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler​(@NotNull
                                                                                                              @NotNull WKWebView webView,
                                                                                                              @NotNull
                                                                                                              @NotNull java.lang.String prompt,
                                                                                                              @Nullable
                                                                                                              @Nullable java.lang.String defaultText,
                                                                                                              @NotNull
                                                                                                              @NotNull WKFrameInfo frame,
                                                                                                              @NotNull
                                                                                                              @NotNull WKUIDelegate.Block_webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler completionHandler)
        Displays a JavaScript text input panel. For user security, your app should call attention to the fact that a specific website controls the content in this panel. A simple forumla for identifying the controlling website is frame.request.URL.host. The panel should have two buttons, such as OK and Cancel, and a field in which to enter text. If you do not implement this method, the web view will behave as if the user selected the Cancel button.
        Parameters:
        webView - The web view invoking the delegate method.
        prompt - The prompt to display.
        defaultText - The initial text to display in the text entry field.
        frame - Information about the frame whose JavaScript initiated this call.
        completionHandler - The completion handler to call after the text input panel has been dismissed. Pass the entered text if the user chose OK, otherwise nil.
      • webViewShouldPreviewElement

        @Deprecated
        default boolean webViewShouldPreviewElement​(@NotNull
                                                    @NotNull WKWebView webView,
                                                    @NotNull
                                                    @NotNull WKPreviewElementInfo elementInfo)
        Deprecated.
        Allows your app to determine whether or not the given element should show a preview. To disable previews entirely for the given element, return NO. Returning NO will prevent webView:previewingViewControllerForElement:defaultActions: and webView:commitPreviewingViewController: from being invoked. This method will only be invoked for elements that have default preview in WebKit, which is limited to links. In the future, it could be invoked for additional elements. API-Since: 10.0 Deprecated-Since: 13.0
        Parameters:
        webView - The web view invoking the delegate method.
        elementInfo - The elementInfo for the element the user has started touching.
      • webViewDidClose

        default void webViewDidClose​(@NotNull
                                     @NotNull WKWebView webView)
        Notifies your app that the DOM window object's close() method completed successfully. Your app should remove the web view from the view hierarchy and update the UI as needed, such as by closing the containing browser tab or window. API-Since: 9.0
        Parameters:
        webView - The web view invoking the delegate method.
      • webViewContextMenuConfigurationForElementCompletionHandler

        default void webViewContextMenuConfigurationForElementCompletionHandler​(@NotNull
                                                                                @NotNull WKWebView webView,
                                                                                @NotNull
                                                                                @NotNull WKContextMenuElementInfo elementInfo,
                                                                                @NotNull
                                                                                @NotNull WKUIDelegate.Block_webViewContextMenuConfigurationForElementCompletionHandler completionHandler)
        Called when a context menu interaction begins.
        Parameters:
        webView - The web view invoking the delegate method.
        elementInfo - The elementInfo for the element the user is touching.
        completionHandler - A completion handler to call once a it has been decided whether or not to show a context menu. Pass a valid UIContextMenuConfiguration to show a context menu, or pass nil to not show a context menu. API-Since: 13.0
      • webViewContextMenuDidEndForElement

        default void webViewContextMenuDidEndForElement​(@NotNull
                                                        @NotNull WKWebView webView,
                                                        @NotNull
                                                        @NotNull WKContextMenuElementInfo elementInfo)
        Called when the context menu ends, either by being dismissed or when a menu action is taken.
        Parameters:
        webView - The web view invoking the delegate method.
        elementInfo - The elementInfo for the element the user is touching. API-Since: 13.0
      • webViewContextMenuForElementWillCommitWithAnimator

        default void webViewContextMenuForElementWillCommitWithAnimator​(@NotNull
                                                                        @NotNull WKWebView webView,
                                                                        @NotNull
                                                                        @NotNull WKContextMenuElementInfo elementInfo,
                                                                        @NotNull
                                                                        @NotNull UIContextMenuInteractionCommitAnimating animator)
        Called when the context menu configured by the UIContextMenuConfiguration from webView:contextMenuConfigurationForElement:completionHandler: is committed. That is, when the user has selected the view provided in the UIContextMenuContentPreviewProvider.
        Parameters:
        webView - The web view invoking the delegate method.
        elementInfo - The elementInfo for the element the user is touching.
        animator - The animator to use for the commit animation. API-Since: 13.0
      • webViewContextMenuWillPresentForElement

        default void webViewContextMenuWillPresentForElement​(@NotNull
                                                             @NotNull WKWebView webView,
                                                             @NotNull
                                                             @NotNull WKContextMenuElementInfo elementInfo)
        Called when the context menu will be presented.
        Parameters:
        webView - The web view invoking the delegate method.
        elementInfo - The elementInfo for the element the user is touching. API-Since: 13.0
      • webViewRequestDeviceOrientationAndMotionPermissionForOriginInitiatedByFrameDecisionHandler

        default void webViewRequestDeviceOrientationAndMotionPermissionForOriginInitiatedByFrameDecisionHandler​(@NotNull
                                                                                                                @NotNull WKWebView webView,
                                                                                                                @NotNull
                                                                                                                @NotNull WKSecurityOrigin origin,
                                                                                                                @NotNull
                                                                                                                @NotNull WKFrameInfo frame,
                                                                                                                @NotNull
                                                                                                                @NotNull WKUIDelegate.Block_webViewRequestDeviceOrientationAndMotionPermissionForOriginInitiatedByFrameDecisionHandler decisionHandler)
        Allows your app to determine whether or not the given security origin should have access to the device's orientation and motion.
        Parameters:
        securityOrigin - The security origin which requested access to the device's orientation and motion.
        frame - The frame that initiated the request.
        decisionHandler - The decision handler to call once the app has made its decision. API-Since: 15.0
      • webViewRequestMediaCapturePermissionForOriginInitiatedByFrameTypeDecisionHandler

        default void webViewRequestMediaCapturePermissionForOriginInitiatedByFrameTypeDecisionHandler​(@NotNull
                                                                                                      @NotNull WKWebView webView,
                                                                                                      @NotNull
                                                                                                      @NotNull WKSecurityOrigin origin,
                                                                                                      @NotNull
                                                                                                      @NotNull WKFrameInfo frame,
                                                                                                      long type,
                                                                                                      @NotNull
                                                                                                      @NotNull WKUIDelegate.Block_webViewRequestMediaCapturePermissionForOriginInitiatedByFrameTypeDecisionHandler decisionHandler)
        A delegate to request permission for microphone audio and camera video access. If not implemented, the result is the same as calling the decisionHandler with WKPermissionDecisionPrompt. API-Since: 15.0
        Parameters:
        webView - The web view invoking the delegate method.
        origin - The origin of the page.
        frame - Information about the frame whose JavaScript initiated this call.
        type - The type of capture (camera, microphone).
        decisionHandler - The completion handler to call once the decision is made
      • webViewShowLockdownModeFirstUseMessageCompletionHandler

        default void webViewShowLockdownModeFirstUseMessageCompletionHandler​(@NotNull
                                                                             @NotNull WKWebView webView,
                                                                             @NotNull
                                                                             @NotNull java.lang.String message,
                                                                             @NotNull
                                                                             @NotNull WKUIDelegate.Block_webViewShowLockdownModeFirstUseMessageCompletionHandler completionHandler)
        Displays a Lockdown Mode warning panel. The panel should have a single OK button. If you do not implement this method, the web view will display the default Lockdown Mode message. API-Since: 13.0
        Parameters:
        webView - The web view invoking the delegate method.
        message - The message WebKit would display if this delegate were not invoked.
        completionHandler - The completion handler you must invoke to resume after the first use message is displayed.
      • webViewWillDismissEditMenuWithAnimator

        default void webViewWillDismissEditMenuWithAnimator​(@NotNull
                                                            @NotNull WKWebView webView,
                                                            @NotNull
                                                            @NotNull UIEditMenuInteractionAnimating animator)
        Called when the web view is about to dismiss its edit menu.
        Parameters:
        webView - The web view displaying the menu.
        animator - Dismissal animator. Add animations to this object to run them alongside the dismissal transition. API-Since: 16.4
      • webViewWillPresentEditMenuWithAnimator

        default void webViewWillPresentEditMenuWithAnimator​(@NotNull
                                                            @NotNull WKWebView webView,
                                                            @NotNull
                                                            @NotNull UIEditMenuInteractionAnimating animator)
        Called when the web view is about to present its edit menu.
        Parameters:
        webView - The web view displaying the menu.
        animator - Appearance animator. Add animations to this object to run them alongside the appearance transition. API-Since: 16.4