www.2527.com_澳门新葡8455手机版_新京葡娱乐场网址_
做最好的网站

WKWebView简单使用

2019-08-09 03:23 来源:未知

WKWebView轻易使用,wkwebview

 如今有空看了弹指间 WKWebView ,就把温馨计算的笔录一下,方便查看.

注:一下为个体计算,会有不足,热烈接待大神教导

1> 创建
导入:#import <WebKit/WebKit.h>
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"];
[self.view addSubview:webView];

2> WKWebView的代理有四个 
WKUIDelegate,WKNavigationDelegate,WKScriptMessageHandler

3> 代理方法
3.1> WKUIDelegate的代办方法
/** 成立新的webView 钦定布署对象、导航动作对象、window性子 */
-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{}
/** 展现三个与JS交互的确认Alert(弹框) */

  • (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler{}
    /** 弹出叁个输入框(与JS交互的) */
  • (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler{}
    /** 显示二个与JS交互的警告Alert(弹框) */
  • (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler{}
    /** webview关闭时的回调 */
  • (void)webViewDidClose:(WKWebView *)webView{}
    3.2> WKNavigationDelegate代理方法
    #pragma mark 导航监听
    /** 在出殡和埋葬哀告在此之前,决定是或不是跳转 */
  • (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{}
    /** 收到身份验证 */
  • (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{}
    /** 在收到响应后,决定是还是不是跳转 */
  • (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{}
    /** 接收到服务器跳转央求之后再实践 */
  • (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载战败 */
  • (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{}
    /** WKWebView终止 */
  • (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView{}

#pragma mark 网页监听
/** 页面起首加载 */

  • (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 当内容开端回来时调用 */
  • (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载成功未来调用 */
  • (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载失败时调用 */
  • (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{}

3.3> WKScriptMessageHandler代理方法
/** 网页通过JS把消息发送给OC */

  • (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{}

近日悠闲看了一晃WKWebView ,就把温馨总结的笔录一下,方便查看. 注:一下为当中华全国体育总会计,会有不足,热烈迎接大神指引...

 方今悠闲看了刹那间 WKWebView ,就把温馨总括的记录一下,方便查看.

 方今没事看了眨眼之间间 WKWebView ,就把团结总括的记录一下,方便查看.

注:一下为私家总计,会有欠缺,热烈应接大神辅导

注:一下为个体计算,会有欠缺,热烈接待大神教导

1> 创建
导入:#import <WebKit/WebKit.h>
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"];
[self.view addSubview:webView];

1> 创建
导入:#import <WebKit/WebKit.h>
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"];
[self.view addSubview:webView];

2> WKWebView的代理有两个 
WKUIDelegate,WKNavigationDelegate,WKScriptMessageHandler

2> WKWebView的代办有多少个 
WKUIDelegate,WKNavigationDelegate,WKScriptMessageHandler

3> 代理方法
3.1> WKUIDelegate的代办方法
/** 成立新的webView 钦定布署对象、导航动作对象、window个性 */
-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{}
/** 突显一个与JS交互的确认Alert(弹框) */

3> 代理方法
3.1> WKUIDelegate的代办方法
/** 成立新的webView 指定安顿对象、导航动作对象、window性格 */
-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{}
/** 展现贰个与JS交互的确认Alert(弹框) */

  • (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler{}
    /** 弹出二个输入框(与JS交互的) */
  • (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler{}
    /** 展现二个与JS交互的警告Alert(弹框) */
  • (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler{}
    /** webview关闭时的回调 */
  • (void)webViewDidClose:(WKWebView *)webView{}
    3.2> WKNavigationDelegate代理方法
    #pragma mark 导航监听
    /** 在发送要求在此之前,决定是不是跳转 */
  • (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{}
    /** 收到身份验证 */
  • (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{}
    /** 在接到响应后,决定是还是不是跳转 */
  • (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{}
    /** 接收到服务器跳转伏乞之后再实行 */
  • (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载失利 */
  • (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{}
    /** WKWebView终止 */
  • (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView{}
  • (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler{}
    /** 弹出三个输入框(与JS交互的) */
  • (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler{}
    /** 呈现二个与JS交互的警告Alert(弹框) */
  • (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler{}
    /** webview关闭时的回调 */
  • (void)webViewDidClose:(WKWebView *)webView{}
    3.2> WKNavigationDelegate代理方法
    #pragma mark 导航监听
    /** 在出殡和埋葬须要此前,决定是或不是跳转 */
  • (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{}
    /** 收到身份验证 */
  • (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{}
    /** 在吸收响应后,决定是或不是跳转 */
  • (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{}
    /** 接收到服务器跳转央浼之后再实施 */
  • (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载失利 */
  • (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{}
    /** WKWebView终止 */
  • (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView{}

#pragma mark 网页监听
/** 页面初叶加载 */

#pragma mark 网页监听
/** 页面起始加载 */

  • (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 当内容开头回到时调用 */
  • (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载成功之后调用 */
  • (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载失利时调用 */
  • (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{}
  • (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 当内容伊始回到时调用 */
  • (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载成功之后调用 */
  • (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{}
    /** 页面加载退步时调用 */
  • (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{}

3.3> WKScriptMessageHandler代理方法
/** 网页通过JS把音信发送给OC */

3.3> WKScriptMessageHandler代理方法
/** 网页通过JS把音信发送给OC */

  • (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{}
  • (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{}
TAG标签:
版权声明:本文由澳门新葡8455手机版发布于新京葡娱乐场网址,转载请注明出处:WKWebView简单使用