Ios 如何覆盖WKWebView的loadRequest
我想创建一个自定义Ios 如何覆盖WKWebView的loadRequest,ios,swift,wkwebview,Ios,Swift,Wkwebview,我想创建一个自定义WKWebView类,因为我想设置一个自定义HTTP头。但我得到了这个错误: 使用选择器“loadRequest:”重写的方法具有不兼容的类型“(NSURLRequest)->WKNavigation?” 它是这样写在“wkwebview”类中的 @availability(iOS, introduced=8.0) class WKWebView : UIView { /*! @abstract A copy of the configuration with whi
WKWebView
类,因为我想设置一个自定义HTTP
头。但我得到了这个错误:
使用选择器“loadRequest:”重写的方法具有不兼容的类型“(NSURLRequest)->WKNavigation?”
它是这样写在“wkwebview”类中的
@availability(iOS, introduced=8.0)
class WKWebView : UIView {
/*! @abstract A copy of the configuration with which the web view was
initialized. */
@NSCopying var configuration: WKWebViewConfiguration { get }
/*! @abstract The web view's navigation delegate. */
weak var navigationDelegate: WKNavigationDelegate?
/*! @abstract The web view's user interface delegate. */
weak var UIDelegate: WKUIDelegate?
/*! @abstract The web view's back-forward list. */
var backForwardList: WKBackForwardList { get }
/*! @abstract Returns a web view initialized with a specified frame and
configuration.
@param frame The frame for the new web view.
@param configuration The configuration for the new web view.
@result An initialized web view, or nil if the object could not be
initialized.
@discussion This is a designated initializer. You can use
@link -initWithFrame: @/link to initialize an instance with the default
configuration. The initializer copies the specified configuration, so
mutating the configuration after invoking the initializer has no effect
on the web view.
*/
init(frame: CGRect, configuration: WKWebViewConfiguration)
/*! @abstract Navigates to a requested URL.
@param request The request specifying the URL to which to navigate.
@result A new navigation for the given request.
*/
func loadRequest(request: NSURLRequest) -> WKNavigation?
/*! @abstract Sets the webpage contents and base URL.
@param string The string to use as the contents of the webpage.
@param baseURL A URL that is used to resolve relative URLs within the document.
@result A new navigation.
*/
func loadHTMLString(string: String, baseURL: NSURL?) -> WKNavigation?
/*! @abstract Navigates to an item from the back-forward list and sets it
as the current item.
@param item The item to which to navigate. Must be one of the items in the
web view's back-forward list.
@result A new navigation to the requested item, or nil if it is already
the current item or is not part of the web view's back-forward list.
@seealso backForwardList
*/
func goToBackForwardListItem(item: WKBackForwardListItem) -> WKNavigation?
/*! @abstract The page title.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
*/
var title: String? { get }
/*! @abstract The active URL.
@discussion This is the URL that should be reflected in the user
interface.
@link WKWebView @/link is key-value observing (KVO) compliant for this
property.
*/
@NSCopying var URL: NSURL? { get }
/*! @abstract A Boolean value indicating whether the view is currently
loading content.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
*/
var loading: Bool { get }
/*! @abstract An estimate of what fraction of the current navigation has been completed.
@discussion This value ranges from 0.0 to 1.0 based on the total number of
bytes expected to be received, including the main document and all of its
potential subresources. After a navigation completes, the value remains at 1.0
until a new navigation starts, at which point it is reset to 0.0.
@link WKWebView @/link is key-value observing (KVO) compliant for this
property.
*/
var estimatedProgress: Double { get }
/*! @abstract A Boolean value indicating whether all resources on the page
have been loaded over securely encrypted connections.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
*/
var hasOnlySecureContent: Bool { get }
/*! @abstract A Boolean value indicating whether there is a back item in
the back-forward list that can be navigated to.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
@seealso backForwardList.
*/
var canGoBack: Bool { get }
/*! @abstract A Boolean value indicating whether there is a forward item in
the back-forward list that can be navigated to.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
@seealso backForwardList.
*/
var canGoForward: Bool { get }
/*! @abstract Navigates to the back item in the back-forward list.
@result A new navigation to the requested item, or nil if there is no back
item in the back-forward list.
*/
func goBack() -> WKNavigation?
/*! @abstract Navigates to the forward item in the back-forward list.
@result A new navigation to the requested item, or nil if there is no
forward item in the back-forward list.
*/
func goForward() -> WKNavigation?
/*! @abstract Reloads the current page.
@result A new navigation representing the reload.
*/
func reload() -> WKNavigation?
/*! @abstract Reloads the current page, performing end-to-end revalidation
using cache-validating conditionals if possible.
@result A new navigation representing the reload.
*/
func reloadFromOrigin() -> WKNavigation?
/*! @abstract Stops loading all resources on the current page.
*/
func stopLoading()
/* @abstract Evaluates the given JavaScript string.
@param javaScriptString The JavaScript string to evaluate.
@param completionHandler A block to invoke when script evaluation completes or fails.
@discussion The completionHandler is passed the result of the script evaluation or an error.
*/
func evaluateJavaScript(javaScriptString: String, completionHandler: ((AnyObject!, NSError!) -> Void)?)
/*! @abstract A Boolean value indicating whether horizontal swipe gestures
will trigger back-forward list navigations.
@discussion The default value is NO.
*/
var allowsBackForwardNavigationGestures: Bool
/*! @abstract The scroll view associated with the web view.
*/
var scrollView: UIScrollView { get }
}
如何编写方法与我的代码相同
我只是根据建议写的
我不知道为什么我不能超越
我该怎么办
下面的捕获就是这个错误
什么版本的Xcode?我已经将您的示例一字不差地复制并编译到Xcode 6.4中。你尝试过清理和重新构建吗?真的吗?我的Xcode版本是6.4。但是我仍然有错误。根据此页面,我无法在wkwebview上添加自定义标题。什么版本的Xcode?我已经将您的示例一字不差地复制并编译到Xcode 6.4中。你尝试过清理和重新构建吗?真的吗?我的Xcode版本是6.4。但是我仍然有错误。根据此页面,我无法在wkwebview上添加自定义标题。
@availability(iOS, introduced=8.0)
class WKWebView : UIView {
/*! @abstract A copy of the configuration with which the web view was
initialized. */
@NSCopying var configuration: WKWebViewConfiguration { get }
/*! @abstract The web view's navigation delegate. */
weak var navigationDelegate: WKNavigationDelegate?
/*! @abstract The web view's user interface delegate. */
weak var UIDelegate: WKUIDelegate?
/*! @abstract The web view's back-forward list. */
var backForwardList: WKBackForwardList { get }
/*! @abstract Returns a web view initialized with a specified frame and
configuration.
@param frame The frame for the new web view.
@param configuration The configuration for the new web view.
@result An initialized web view, or nil if the object could not be
initialized.
@discussion This is a designated initializer. You can use
@link -initWithFrame: @/link to initialize an instance with the default
configuration. The initializer copies the specified configuration, so
mutating the configuration after invoking the initializer has no effect
on the web view.
*/
init(frame: CGRect, configuration: WKWebViewConfiguration)
/*! @abstract Navigates to a requested URL.
@param request The request specifying the URL to which to navigate.
@result A new navigation for the given request.
*/
func loadRequest(request: NSURLRequest) -> WKNavigation?
/*! @abstract Sets the webpage contents and base URL.
@param string The string to use as the contents of the webpage.
@param baseURL A URL that is used to resolve relative URLs within the document.
@result A new navigation.
*/
func loadHTMLString(string: String, baseURL: NSURL?) -> WKNavigation?
/*! @abstract Navigates to an item from the back-forward list and sets it
as the current item.
@param item The item to which to navigate. Must be one of the items in the
web view's back-forward list.
@result A new navigation to the requested item, or nil if it is already
the current item or is not part of the web view's back-forward list.
@seealso backForwardList
*/
func goToBackForwardListItem(item: WKBackForwardListItem) -> WKNavigation?
/*! @abstract The page title.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
*/
var title: String? { get }
/*! @abstract The active URL.
@discussion This is the URL that should be reflected in the user
interface.
@link WKWebView @/link is key-value observing (KVO) compliant for this
property.
*/
@NSCopying var URL: NSURL? { get }
/*! @abstract A Boolean value indicating whether the view is currently
loading content.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
*/
var loading: Bool { get }
/*! @abstract An estimate of what fraction of the current navigation has been completed.
@discussion This value ranges from 0.0 to 1.0 based on the total number of
bytes expected to be received, including the main document and all of its
potential subresources. After a navigation completes, the value remains at 1.0
until a new navigation starts, at which point it is reset to 0.0.
@link WKWebView @/link is key-value observing (KVO) compliant for this
property.
*/
var estimatedProgress: Double { get }
/*! @abstract A Boolean value indicating whether all resources on the page
have been loaded over securely encrypted connections.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
*/
var hasOnlySecureContent: Bool { get }
/*! @abstract A Boolean value indicating whether there is a back item in
the back-forward list that can be navigated to.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
@seealso backForwardList.
*/
var canGoBack: Bool { get }
/*! @abstract A Boolean value indicating whether there is a forward item in
the back-forward list that can be navigated to.
@discussion @link WKWebView @/link is key-value observing (KVO) compliant
for this property.
@seealso backForwardList.
*/
var canGoForward: Bool { get }
/*! @abstract Navigates to the back item in the back-forward list.
@result A new navigation to the requested item, or nil if there is no back
item in the back-forward list.
*/
func goBack() -> WKNavigation?
/*! @abstract Navigates to the forward item in the back-forward list.
@result A new navigation to the requested item, or nil if there is no
forward item in the back-forward list.
*/
func goForward() -> WKNavigation?
/*! @abstract Reloads the current page.
@result A new navigation representing the reload.
*/
func reload() -> WKNavigation?
/*! @abstract Reloads the current page, performing end-to-end revalidation
using cache-validating conditionals if possible.
@result A new navigation representing the reload.
*/
func reloadFromOrigin() -> WKNavigation?
/*! @abstract Stops loading all resources on the current page.
*/
func stopLoading()
/* @abstract Evaluates the given JavaScript string.
@param javaScriptString The JavaScript string to evaluate.
@param completionHandler A block to invoke when script evaluation completes or fails.
@discussion The completionHandler is passed the result of the script evaluation or an error.
*/
func evaluateJavaScript(javaScriptString: String, completionHandler: ((AnyObject!, NSError!) -> Void)?)
/*! @abstract A Boolean value indicating whether horizontal swipe gestures
will trigger back-forward list navigations.
@discussion The default value is NO.
*/
var allowsBackForwardNavigationGestures: Bool
/*! @abstract The scroll view associated with the web view.
*/
var scrollView: UIScrollView { get }
}