Class

WKWebView

A WKWebView object displays interactive web content, such as for an in-app browser. You can use the WKWebView class to embed web content in your app. To do so, create a WKWebView object, set it as the view, and send it a request to load web content.

Overview

After creating a new WKWebView object using the initWithFrame:configuration: method, you need to load the web content. Use the loadHTMLString:baseURL: method to begin loading local HTML files or the loadRequest: method to begin loading web content. Use the stopLoading method to stop loading, and the loading property to find out if a web view is in the process of loading. Set the delegate property to an object conforming to the WKUIDelegate protocol to track the loading of web content.

To allow the user to move back and forward through the webpage history, use the goBack and goForward methods as actions for buttons. Use the canGoBack and canGoForward properties to disable the buttons when the user can’t move in a direction.

By default, a web view automatically converts telephone numbers that appear in web content to Phone links. When a Phone link is tapped, the Phone app launches and dials the number. To turn off this default behavior, set the dataDetectorTypes property with a WKDataDetectorTypes bitfield that does not contain the WKDataDetectorTypePhoneNumber flag.

You can also use the setMagnification:centeredAtPoint: to programmatically set the scale of web content the first time it is displayed in a web view. Thereafter, the user can change the scale using gestures.

Symbols

Initializing a Web View

configuration

A copy of the configuration to initialize the web view with.

- initWithFrame:configuration:

Returns a web view initialized with a specified frame and configuration.

- initWithCoder:

Inspecting the View Information

scrollView

The scroll view associated with the web view.

title

The page title.

URL

The active URL.

customUserAgent

The custom user agent string.

serverTrust

A SecTrustRef object for the currently committed navigation.

certificateChain

An array of objects forming the certificate chain for the currently committed navigation.

Deprecated

Setting Delegates

navigationDelegate

The web view's navigation delegate.

UIDelegate

The web view's user interface delegate.

Loading Content

estimatedProgress

An estimate of what fraction of the current navigation has been loaded.

hasOnlySecureContent

A Boolean value indicating whether all resources on the page have been loaded through securely encrypted connections.

- loadHTMLString:baseURL:

Sets the webpage contents and base URL.

loading

A Boolean value indicating whether the view is currently loading content.

- reload

Reloads the current page.

- reloadFromOrigin

Reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible.

- stopLoading

Stops loading all resources on the current page.

- loadData:MIMEType:characterEncodingName:baseURL:

Sets the webpage contents and base URL.

- loadFileURL:allowingReadAccessToURL:

Navigates to the requested file URL on the filesystem

Scaling Content

allowsMagnification

A Boolean value indicating whether magnify gestures will change the web view’s magnification.

magnification

The factor by which the page content is currently scaled.

- setMagnification:centeredAtPoint:

Scales the page content by a specified factor and centers the result on a specified point.

Navigating

allowsBackForwardNavigationGestures

A Boolean value indicating whether horizontal swipe gestures will trigger back-forward list navigations.

backForwardList

The web view's back-forward list.

canGoBack

A Boolean value indicating whether there is a back item in the back-forward list that can be navigated to.

canGoForward

A Boolean value indicating whether there is a forward item in the back-forward list that can be navigated to.

allowsLinkPreview

A Boolean value that determines whether pressing on a link displays a preview of the destination for the link.

- goBack

Navigates to the back item in the back-forward list.

- goForward

Navigates to the forward item in the back-forward list.

- goToBackForwardListItem:

Navigates to an item from the back-forward list and sets it as the current item.

- loadRequest:

Navigates to a requested URL.

Executing JavaScript

- evaluateJavaScript:completionHandler:

Evaluates a JavaScript string.

Instance Methods

- goBack:

Navigates to the back item in the back-forward list.

- goForward:

Navigates to the forward item in the back-forward list.

- reload:

Reloads the current page.

- reloadFromOrigin:

Reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible.

- stopLoading:

Stops loading all resources on the current page.

Relationships

Inherits From