Mac Developer Library

Developer

WebKit Framework Reference WebResourceLoadDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

WebResourceLoadDelegate

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import WebKit

Objective-C

@import WebKit;

Availability


Available in OS X v10.2 and later.

Web view resource load delegates implement this informal protocol to be notified on the progress of loading individual resources. Note that there can be hundreds of resources, such as images and other media, per page. So, if you just want to get page loading status see the WebFrameLoadDelegate protocol.

There’s a separate client request and server response made for each resource on a page. By implementing the webView:identifierForInitialRequest:fromDataSource: method, resource load delegates provide a tracking object used to identify individual resources in subsequent calls to delegate methods. Delegates are then notified when resource loading starts, when data is incrementally received, when any load errors occur, and when the load is complete. Delegates may also change a request before it is sent. In some cases, depending on the page content and server redirects, methods defined in this protocol may be invoked multiple times (see individual method descriptions for more details). All the methods in this protocol are optional.

  • Returns an identifier object used to track the progress of loading a single resource.

    Declaration

    Swift

    func webView(_ sender: WebView!, identifierForInitialRequest request: NSURLRequest!, fromDataSource dataSource: WebDataSource!) -> AnyObject!

    Objective-C

    - (id)webView:(WebView *)sender identifierForInitialRequest:(NSURLRequest *)request fromDataSource:(WebDataSource *)dataSource

    Parameters

    sender

    The web view that sent this message.

    request

    The request that initiated this load for dataSource.

    dataSource

    The data source for this web view.

    Return Value

    An identifier object that is retained by sender and passed as a parameter to all other delegate messages pertaining to this resource.

    Discussion

    Delegates might implement this method to begin tracking the progress of loading an individual resource. Note that this method is invoked once per load where as the webView:resource:willSendRequest:redirectResponse:fromDataSource: method may be invoked multiple times.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 and later.

  • Invoked before a request is initiated for a resource and returns a possibly modified request.

    Declaration

    Swift

    func webView(_ sender: WebView!, resource identifier: AnyObject!, willSendRequest request: NSURLRequest!, redirectResponse redirectResponse: NSURLResponse!, fromDataSource dataSource: WebDataSource!) -> NSURLRequest!

    Objective-C

    - (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource

    Parameters

    sender

    The web view that sent this message.

    identifier

    An identifier object used to track the resource being loaded by dataSource.

    request

    The request that is sent.

    redirectResponse

    The redirect server response. If nil, there is no redirect in progress.

    dataSource

    The data source for this web view.

    Return Value

    A possibly modified request.

    Discussion

    Delegates might implement this method to modify resource requests before they are sent. Note that this method might be invoked multiple times per load (as a result of a server redirect) where as the webView:identifierForInitialRequest:fromDataSource: method is invoked once.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 and later.

  • Invoked when all of the data for a given resource is loaded.

    Declaration

    Swift

    func webView(_ sender: WebView!, resource identifier: AnyObject!, didFinishLoadingFromDataSource dataSource: WebDataSource!)

    Objective-C

    - (void)webView:(WebView *)sender resource:(id)identifier didFinishLoadingFromDataSource:(WebDataSource *)dataSource

    Parameters

    sender

    The web view that sent this message.

    identifier

    An identifier object used to track the resource being loaded by dataSource.

    dataSource

    The data source for this web view.

    Discussion

    The identifier parameter is used to track the resource being loaded by dataSource. Delegates might implement this method to update the load status of an individual resource.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 and later.

  • Invoked after a resource has been loaded.

    Declaration

    Swift

    func webView(_ sender: WebView!, resource identifier: AnyObject!, didReceiveResponse response: NSURLResponse!, fromDataSource dataSource: WebDataSource!)

    Objective-C

    - (void)webView:(WebView *)sender resource:(id)identifier didReceiveResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)dataSource

    Parameters

    sender

    The web view that sent this message.

    identifier

    An identifier object used to track the resource being loaded by dataSource.

    response

    The reply that was received.

    dataSource

    The data source for this web view.

    Discussion

    In some rare cases, multiple responses may be received for a single resource. This happens in the case of multipart/x-mixed-replace, also known as a server push. In this case, delegates should assume that the progress of loading this resource restarts, and the expected content length may change.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 and later.

  • Invoked when some of the data for a given resource has arrived.

    Declaration

    Swift

    func webView(_ sender: WebView!, resource identifier: AnyObject!, didReceiveContentLength length: Int, fromDataSource dataSource: WebDataSource!)

    Objective-C

    - (void)webView:(WebView *)sender resource:(id)identifier didReceiveContentLength:(NSInteger)length fromDataSource:(WebDataSource *)dataSource

    Parameters

    sender

    The web view that sent this message.

    identifier

    An identifier object used to track the resource being loaded by dataSource.

    length

    The amount of incremental data received for this resource—the amount of data loaded since the last time this method was invoked for this resource, not the total amount received for this resource.

    The length parameter type was changed from type unsigned int to type NSUInteger in Mac OS X v10.5.

    dataSource

    The data source for this web view.

    Discussion

    Delegates might implement this method to update the load status of an individual resource.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 and later.

  • Invoked when a resource failed to load.

    Declaration

    Swift

    func webView(_ sender: WebView!, resource identifier: AnyObject!, didFailLoadingWithError error: NSError!, fromDataSource dataSource: WebDataSource!)

    Objective-C

    - (void)webView:(WebView *)sender resource:(id)identifier didFailLoadingWithError:(NSError *)error fromDataSource:(WebDataSource *)dataSource

    Parameters

    sender

    The web view that sent this message.

    identifier

    An identifier object used to track the resource being loaded by dataSource.

    error

    The error that occurred loading that resource.

    dataSource

    The data source for this web view.

    Discussion

    Delegates might implement this method to display or log a detailed error message.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 and later.

  • Invoked when a plug-in fails to load.

    Declaration

    Swift

    func webView(_ sender: WebView!, plugInFailedWithError error: NSError!, dataSource dataSource: WebDataSource!)

    Objective-C

    - (void)webView:(WebView *)sender plugInFailedWithError:(NSError *)error dataSource:(WebDataSource *)dataSource

    Parameters

    sender

    The web view that sent this message.

    error

    The error that occurred during the process of loading that resource.

    The userInfo dictionary of error may contain additional information about the failure. If the userInfo dictionary is not nil, it may contain some or all of these key-value pairs. The value of the NSErrorFailingURLKey key is a URL string of the SRC attribute. The value of the WebKitErrorPlugInNameKey key is a string containing the plug-in's name. The value for the WebKitErrorPlugInPageURLStringKey key is a URL string of the PLUGINSPAGE attribute. The value of the WebKitErrorMIMETypeKey key is a string of the TYPE attribute.

    dataSource

    The data source for this web view.

    Discussion

    This method might be invoked if a plug-in is not found, fails to load, or is not available for some reason. Delegates might implement this method to display or log a detailed error message. If you do not implement this method, no action is taken.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 and later.