Code Monkey home page Code Monkey logo

wkwebviewcontroller's Introduction

WKWebViewController

对iOS WKWebView的二次封装,更方便的使用WkWebView。

特性

  • 增强的Javascript和Native代码交互
  • 简单的Cookie设置方法
  • 支持加载进度条和前进后退操作
  • 支持Web页面错误信息和Log输出
  • 可清理WebView缓存

构成和使用方法

功能 WKWebViewController WKWebViewControllerEx
JS交互
错误/Log输出
Cookie设置
进度条
前进/后退

运行Demo

  1. Docs/html下的文件复制到本机web服务器目录;
  2. /etc/host添加 127.0.0.1 www.test.com, 在浏览器能正常访问 http://www.test.com/wkwebview.html 即可;
  3. 打开 Example/testWKWebView.xcodeproj工程即可看到运行效果;
  4. 更多示例代码请参考Demo或html。

相关代码示例

  1. JS->Native

    window.wkTestObject.testFunc3('arg1', {a:1, b:2}, function(response) {

     alert(response);
     return {a:10};
    

    });

    • WKWebViewController->messageName设置为wkTestObject
    • 添加 -(id)testFunc3(id args) 函数实现

    支持的参数类型Number, String, Array, JSON Object, 最后一个参数可以是function(Native 函数调用后返回值会通过此函数回调过来)

  2. Native->JS

    NSArray *args = @[@"str", @{"key":value}, @[@"item"], @(1)];

    invokeJSFunction(@"testJSFunction", args, completionHandler:completionHandler);

    • 参数一: JS函数名
    • 参数二:参数列表(支持的类型,NSNumber, NSString, NSArray, NSDictionary)
    • 参数三:执行结果回调

安装

将WKWebViewController目录拖入工程,根据需要引用WkWebViewController.hWKWebViewControllerEx.h.

系统要求

iOS 8.0及以上

wkwebviewcontroller's People

Contributors

hoojack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.