WKWebView
A WKWebView object displays interactive web content, such as for an in-app browser.
For new development, employ this class instead of the older UIWebView class.
-
init(frame:configuration:) - initWithFrame:configuration:Designated InitializerReturns a web view initialized with a specified frame and configuration.
Declaration
Swift
init(frameframe: CGRect, configurationconfiguration: WKWebViewConfiguration)Objective-C
- (instancetype)initWithFrame:(CGRect)frameconfiguration:(WKWebViewConfiguration *)configurationParameters
frameThe frame for the new web view.
configurationThe configuration for the new web view.
Return Value
An initialized web view, or
nilif the object could not be initialized.Discussion
This is a designated initializer that accepts a custom
WKWebViewConfiguration. The initializer copies the specified configuration. Changing the configuration object after initializing the web view has no effect on the web view. You can use theinitWithFrame:method to initialize an instance with the default configuration. SeeWKWebViewConfigurationfor default values.Availability
Available in iOS 8.0 and later.
-
configuration configurationPropertyA copy of the configuration to initialize the web view with. (read-only)
Declaration
Swift
@NSCopying var configuration: WKWebViewConfiguration { get }Objective-C
@property(nonatomic, readonly, copy) WKWebViewConfiguration *configurationAvailability
Available in iOS 8.0 and later.
See Also
-
scrollView scrollViewPropertyThe scroll view associated with the web view. (read-only)
Declaration
Swift
var scrollView: UIScrollView { get }Objective-C
@property(nonatomic, readonly, strong) UIScrollView *scrollViewAvailability
Available in iOS 8.0 and later.
-
The active URL. (read-only)
Declaration
Swift
@NSCopying var URL: NSURL? { get }Objective-C
@property(nonatomic, readonly, copy) NSURL *URLDiscussion
This is the URL that should be reflected in the user interface.
The
WKWebViewclass is key-value observing (KVO) compliant for this property.Availability
Available in iOS 8.0 and later.
-
customUserAgent customUserAgentProperty -
certificateChain certificateChainPropertyAn array of objects forming the certificate chain for the currently committed navigation. (read-only)
Declaration
Swift
var certificateChain: [AnyObject] { get }Objective-C
@property(nonatomic, readonly, copy) NSArray *certificateChainDiscussion
Each item in the array is a
SecCertificateRefobject.Availability
Available in iOS 9.0 and later.
-
navigationDelegate navigationDelegatePropertyThe web view's navigation delegate.
Declaration
Swift
weak var navigationDelegate: WKNavigationDelegate?Objective-C
@property(nonatomic, weak) id< WKNavigationDelegate > navigationDelegateAvailability
Available in iOS 8.0 and later.
See Also
-
UIDelegate UIDelegatePropertyThe web view's user interface delegate.
Declaration
Swift
weak var UIDelegate: WKUIDelegate?Objective-C
@property(nonatomic, weak) id< WKUIDelegate > UIDelegateAvailability
Available in iOS 8.0 and later.
See Also
-
estimatedProgress estimatedProgressPropertyAn estimate of what fraction of the current navigation has been loaded. (read-only)
Declaration
Swift
var estimatedProgress: Double { get }Objective-C
@property(nonatomic, readonly) double estimatedProgressDiscussion
This value ranges from
0.0to1.0based on the total number of bytes expected to be received, including the main document and all of its potential subresources. After a navigation loading completes, theestimatedProgressremains at1.0until a new navigation starts, at which point theestimatedProgressis reset to0.0.The
WKWebViewclass is key-value observing (KVO) compliant for this property.Availability
Available in iOS 8.0 and later.
-
hasOnlySecureContent hasOnlySecureContentPropertyA Boolean value indicating whether all resources on the page have been loaded through securely encrypted connections. (read-only)
Declaration
Swift
var hasOnlySecureContent: Bool { get }Objective-C
@property(nonatomic, readonly) BOOL hasOnlySecureContentDiscussion
The
WKWebViewclass is key-value observing (KVO) compliant for this property.Availability
Available in iOS 8.0 and later.
-
Sets the webpage contents and base URL.
Declaration
Swift
func loadHTMLString(_string: String, baseURLbaseURL: NSURL?) -> WKNavigation?Objective-C
- (WKNavigation *)loadHTMLString:(NSString *)stringbaseURL:(NSURL *)baseURLParameters
stringThe string to use as the contents of the webpage.
baseURLA URL used to resolve relative URLs within the document.
Return Value
A new navigation.
Availability
Available in iOS 8.0 and later.
-
A Boolean value indicating whether the view is currently loading content. (read-only)
Declaration
Swift
var loading: Bool { get }Objective-C
@property(nonatomic, readonly, getter=isLoading) BOOL loadingDiscussion
The
WKWebViewclass is key-value observing (KVO) compliant for this property.Availability
Available in iOS 8.0 and later.
-
Reloads the current page.
Return Value
A new navigation representing the reload.
Availability
Available in iOS 8.0 and later.
-
Reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible.
Declaration
Swift
func reloadFromOrigin() -> WKNavigation?Objective-C
- (WKNavigation *)reloadFromOriginReturn Value
A new navigation representing the reload.
Availability
Available in iOS 8.0 and later.
-
Stops loading all resources on the current page.
Declaration
Swift
func stopLoading()Objective-C
- (void)stopLoadingAvailability
Available in iOS 8.0 and later.
-
loadData(_:MIMEType:characterEncodingName:baseURL:) - loadData:MIMEType:characterEncodingName:baseURL:Sets the webpage contents and base URL.
Declaration
Swift
func loadData(_data: NSData, MIMETypeMIMEType: String, characterEncodingNamecharacterEncodingName: String, baseURLbaseURL: NSURL) -> WKNavigation?Objective-C
- (WKNavigation *)loadData:(NSData *)dataMIMEType:(NSString *)MIMETypecharacterEncodingName:(NSString *)characterEncodingNamebaseURL:(NSURL *)baseURLParameters
dataThe data to use as the contents of the webpage.
MIMETypeThe MIME type of the data.
characterEncodingNameThe data's character encoding name.
baseURLA URL used to resolve relative URLs within the document.
Return Value
A new navigation.
Availability
Available in iOS 9.0 and later.
-
Navigates to the requested file URL on the filesystem
Declaration
Swift
func loadFileURL(_URL: NSURL, allowingReadAccessToURLreadAccessURL: NSURL) -> WKNavigation?Objective-C
- (WKNavigation *)loadFileURL:(NSURL *)URLallowingReadAccessToURL:(NSURL *)readAccessURLParameters
URLThe file URL to navigate to.
readAccessURLThe URL to allow read access to.
Return Value
A new navigation for the given file URL.
Discussion
If
readAccessURLreferences a single file, only that file may be loaded by WebKit. IfreadAccessURLreferences a directory, files inside that file may be loaded by WebKit.Availability
Available in iOS 9.0 and later.
-
A Boolean value indicating whether horizontal swipe gestures will trigger back-forward list navigations.
Declaration
Swift
var allowsBackForwardNavigationGestures: BoolObjective-C
@property(nonatomic) BOOL allowsBackForwardNavigationGesturesDiscussion
The default value is
NOfalse.Availability
Available in iOS 8.0 and later.
-
backForwardList backForwardListPropertyThe web view's back-forward list. (read-only)
Declaration
Swift
var backForwardList: WKBackForwardList { get }Objective-C
@property(nonatomic, readonly, strong) WKBackForwardList *backForwardListAvailability
Available in iOS 8.0 and later.
-
A Boolean value indicating whether there is a back item in the back-forward list that can be navigated to. (read-only)
Declaration
Swift
var canGoBack: Bool { get }Objective-C
@property(nonatomic, readonly) BOOL canGoBackAvailability
Available in iOS 8.0 and later.
-
canGoForward canGoForwardPropertyA Boolean value indicating whether there is a forward item in the back-forward list that can be navigated to. (read-only)
Declaration
Swift
var canGoForward: Bool { get }Objective-C
@property(nonatomic, readonly) BOOL canGoForwardAvailability
Available in iOS 8.0 and later.
-
allowsLinkPreview allowsLinkPreviewPropertyA Boolean value that determines whether pressing on a link displays a preview of the destination for the link.
Declaration
Swift
var allowsLinkPreview: BoolObjective-C
@property(nonatomic) BOOL allowsLinkPreviewDiscussion
In iOS this property is available on devices that support 3D Touch. Default value is
NOfalsein iOS.If you set this property’s value to
YEStrue, an iOS user can press links to preview link destinations and detected data such as addresses and phone numbers. Such previews are known to users as peeks. If a user presses deeper on a link preview, the preview navigates (or pops, in user terminology) to the destination. Because pop navigation switches the user from your app to Safari, it is opt-in for iOS apps.If you want to support link preview in iOS but also want to keep users within your app, you can switch from using the
WKWebViewclass to theSFSafariViewControllerclass. If you are using a web view as an in-app browser, making this change is best practice. The Safari view controller class automatically supports link previews.In OS X this property is available on devices with a Force Touch trackpad. Default value is
YEStruein OS X.With this property set to its default value of
YEStrue, an OS X user can force click a link to display a preview window showing the link’s destination. If the user then clicks on the preview, the destination opens in Safari.On both platforms, all types of detected data respond to presses when this property is set to
YEStrue. That is, in iOS 9 and OS X v10.11, you cannot specify which types of data are detected in theWKWebViewclass.Availability
Available in iOS 9.0 and later.
-
Navigates to the back item in the back-forward list.
Return Value
A new navigation to the requested item, or
nilif there is no back item in the back-forward list.Availability
Available in iOS 8.0 and later.
-
Navigates to the forward item in the back-forward list.
Return Value
A new navigation to the requested item, or
nilif there is no forward item in the back-forward list.Availability
Available in iOS 8.0 and later.
-
Navigates to an item from the back-forward list and sets it as the current item.
Declaration
Swift
func goToBackForwardListItem(_item: WKBackForwardListItem) -> WKNavigation?Objective-C
- (WKNavigation *)goToBackForwardListItem:(WKBackForwardListItem *)itemParameters
itemThe item to navigate to. The
itemmust be one of the items in the web view’s back-forward list.Return Value
A new navigation to the requested item, or
nilif it is already the current item or is not part of the web view's back-forward list.Availability
Available in iOS 8.0 and later.
-
Navigates to a requested URL.
Declaration
Swift
func loadRequest(_request: NSURLRequest) -> WKNavigation?Objective-C
- (WKNavigation *)loadRequest:(NSURLRequest *)requestParameters
requestThe request specifying the URL to navigate to.
Return Value
A new navigation for the given request.
Availability
Available in iOS 8.0 and later.
-
Evaluates a JavaScript string.
Declaration
Parameters
javaScriptStringThe JavaScript string to evaluate.
completionHandlerA block to invoke when script evaluation completes or fails.
Discussion
The method sends the result of the script evaluation (or an error) to the completion handler.
Availability
Available in iOS 8.0 and later.
Copyright © 2015 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2015-10-21
