{"id":32323217,"url":"https://github.com/hongruqi/wtwebview","last_synced_at":"2026-02-20T23:02:14.847Z","repository":{"id":56926938,"uuid":"100091978","full_name":"hongruqi/WTWebView","owner":"hongruqi","description":"WKWebView","archived":false,"fork":false,"pushed_at":"2019-06-20T08:50:42.000Z","size":47,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T12:53:54.406Z","etag":null,"topics":["uiwebview","webview","wkwebview"],"latest_commit_sha":null,"homepage":"http://blog.cocoachina.com/article/58278","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hongruqi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-12T05:43:51.000Z","updated_at":"2022-08-14T13:57:17.000Z","dependencies_parsed_at":"2022-08-21T04:20:54.198Z","dependency_job_id":null,"html_url":"https://github.com/hongruqi/WTWebView","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hongruqi/WTWebView","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hongruqi%2FWTWebView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hongruqi%2FWTWebView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hongruqi%2FWTWebView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hongruqi%2FWTWebView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hongruqi","download_url":"https://codeload.github.com/hongruqi/WTWebView/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hongruqi%2FWTWebView/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29667119,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T19:49:36.704Z","status":"ssl_error","status_checked_at":"2026-02-20T19:44:05.372Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["uiwebview","webview","wkwebview"],"created_at":"2025-10-23T12:52:25.633Z","updated_at":"2026-02-20T23:02:14.842Z","avatar_url":"https://github.com/hongruqi.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WTWebView\n\n[![CI Status](http://img.shields.io/travis/lbrsilva-allin/WTWebView.svg?style=flat)](https://travis-ci.org/lbrsilva-allin/WTWebView)\n[![Version](https://img.shields.io/cocoapods/v/WTWebView.svg?style=flat)](http://cocoapods.org/pods/WTWebView)\n[![License](https://img.shields.io/cocoapods/l/WTWebView.svg?style=flat)](http://cocoapods.org/pods/WTWebView)\n[![Platform](https://img.shields.io/cocoapods/p/WTWebView.svg?style=flat)](http://cocoapods.org/pods/WTWebView)\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n## Installation\n\nWTWebView is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"WTWebView\"\n```\n\n## Author\n\n\n## License\n\nWTWebView is available under the MIT license. See the LICENSE file for more info.\n##前言\nWKWebView是在Apple的WWDC 2014发布，将原有UIWebViewDelegate与UIWebView重构成了14类与3个协议。\nWKWebView，在iOS8和OS X 10.10开始支持，是为了解决UIWebView加载速度慢、占用内存大的问题。\n在使用UIWebView加载网页的时候，会出现内存会无限增长，内存泄漏的问题。\nWebKit中WKWebView控件的特性与使用方法，很好的解决了UIWebView存在的内存、加载速度等诸多问题。\n\n## 一、WKWebView 特性\n\n- 占用更少的内存\n- Safari相同的JavaScript引擎\n- 支持了更多的HTML5特性；\n- 支持手势返回\n- 滚动刷新率可达到60fps，堪比native\n\n##webkit\n![WebKit.png](http://upload-images.jianshu.io/upload_images/901318-ed61ead50e44c08d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n##OC与JS交互\nWKWebview提供了API实现js交互 不需要借助JavaScriptCore或者webJavaScriptBridge。\n###WKWebView\nWKWebView对象显示交互式Web内容，例如针对应用内浏览器。 您可以使用WKWebView类将Web内容嵌入到您的应用程序中。 只需要创建一个WKWebView对象，并向其发送加载Web内容的请求。\n**API**\n\n初始化\n\n```ObjC\n- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration\n```\n常用方法\n\n```ObjC\n- (nullable WKNavigation *)loadRequest:(NSURLRequest *)request;\n- (nullable WKNavigation *)loadHTMLString:(NSString *)string baseURL:(nullable NSURL *)baseURL;\n- (nullable WKNavigation *)goBack;\n- (nullable WKNavigation *)goForward;\n// Reloads the current page.\n- (nullable WKNavigation *)reload;\n- (nullable WKNavigation *)reloadFromOrigin;\n```\n\n###WKNavigtionDelegate\n\n```ObjC\n// 页面开始加载时调用\n- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation;\n// 当内容开始返回时调用\n- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation;\n// 页面加载完成之后调用\n- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation;\n// 页面加载失败时调用\n- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation;\n// 接收到服务器跳转请求之后再执行\n- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation;\n// 在收到响应后，决定是否跳转\n- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler;\n// 在发送请求之前，决定是否跳转\n- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;\n\n```\n\n###WKUIDelegate\n\n```ObjC\n//1.创建一个新的WebVeiw\n- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures;\n//2.WebVeiw关闭（9.0中的新方法）\n- (void)webViewDidClose:(WKWebView *)webView NS_AVAILABLE(10_11, 9_0);\n//3.显示一个JS的Alert（与JS交互）\n- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler;\n//4.弹出一个输入框（与JS交互的）\n- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * __nullable result))completionHandler;\n//5.显示一个确认框（JS的）\n- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler;\n```\n\n### JS调用OC\n使用WKUserContentController实现js=\u003enative交互。简单的说就是先注册约定好的方法，然后再调用。\n**流程图：**\n\n```flow\nop=\u003eoperation: 配置环境\nop1=\u003eoperation: 注册方法\nop-\u003eop1\n```\n\n**代码：**\n\n```ObjC\n//配置环境，使用WKWebViewConfiguration\nWKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];\nconfiguration.allowsInlineMediaPlayback = YES;\nWKUserContentController *userContentController = [[WKUserContentController alloc] init];\nconfiguration.userContentController = userContentController;\n//注册方法\n／*\nself.hybrid 是WTWebViewJSBridge类实例，处理js调用native方法\nBridgeName js 方法名\n*／\n[userContentController addScriptMessageHandler:self.hybrid name:BridgeName];\n\n```\n**JS回调处理**\n\n```ObjC\n//WTWebViewJSBridge.m\n- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message\n{\n    if ([message.name isEqualToString:BridgeName]) {\n        if ([message.body isKindOfClass:[NSDictionary class]]) {\n            [self postMessage:message.body];\n        }\n    }\n}\n```  \n\n###OC调用JS\n这个简单多了，直接用WKWebview，evaluateJavaScript方法进行调用\n```ObjC\n- (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler\n{\n    if (self.webkit) {\n        [self.webkit evaluateJavaScript:javaScriptString completionHandler:completionHandler];\n    }\n}\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhongruqi%2Fwtwebview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhongruqi%2Fwtwebview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhongruqi%2Fwtwebview/lists"}