WKWebView

WKWebView

1、WKWebViewConfiguration

进程池

  • WKProcessPool

    处理webView内容加载的进程池。这个类在平时开发中基本没用过。

配置

  • WKPreferences

    设置webView内容最小字体大小,是否可以被注入js脚本等

js交互

  • WKUserContentController

    这个类主要作用是OC与javaScript交互的类。

缓存

  • WKWebsiteDataStore

    这个类主要与浏览器缓存相关。

其他属性…

2、WKNavigationDelegate

开始加载

- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation;

加载失败
- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error;

加载成功
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation;

其他…

3、WKUIDelegate

警告框

- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
    //这里弹警告框后,并将弹窗消息回调到js
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:^{
        //回调
        if (completionHandler) {
            completionHandler();
        }
    }];
}

确认框

- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler {
    //这里弹确认窗
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        //回调取消事件
        if (completionHandler) {
            completionHandler(NO);
        }
    }];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //回调确认事件
        if (completionHandler) {
            completionHandler(YES);
        }
    }];
    [alert addAction:action];
    [alert addAction:action1];
    [self presentViewController:alert animated:YES completion:^{
        
    }];
}

输入框

- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable))completionHandler {
    //...
}

4、WKBackForwardList

很像一个单链表,但是是有序的,节点是WKBackForwardListItem,是通过数组存储的。当前节点currentItem,前一个节点forwardItem,后一个节点backItem。

节点里存储着webView的URL,title信息。

这个类是webView page管理类,每个page以一个WKBackForwardListItem对象存储,有backList和forwardList两个数组分别存储之前和之后的webPage。当前的直接用currentItem属性可以取到。

当前节点
@property (nullable, nonatomic, readonly, strong) WKBackForwardListItem *currentItem;

前一个节点
@property (nullable, nonatomic, readonly, strong) WKBackForwardListItem *forwardItem;

后一个节点
@property (nullable, nonatomic, readonly, strong) WKBackForwardListItem *backItem;

5、其他

略…

参考资料:
WKWebView详解
WKWebView代理方法解析

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Morris_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值