Code Monkey home page Code Monkey logo

app-link's Introduction

Applink


提供H5页面和客户端通讯的机制。提供webview中js调用IOS,Andriod内部方法的机制。提供事件机制,方便Native对js的调用。

如何使用

1.0.0

window.applink.invoke("class", "function", params, success, fail, timeout);

1.1.0

Applink 类为单例模式
初始化对象,调用native

//初始化参数 协议头部 超时时间 
let applink = new Applink("aplink", 60 * 1000 * 10);  
applink.invoke("class", "function", params, success, fail, timeout);

利用事件native调用H5
H5注册事件, 客户端只需要调用applink.fireEvent方法,来触发H5的JS

document.addEventListener('eventName', function(data) {
	// 这里要注意,Native 传递过来的事件参数是在 data 的 param 属性中。
	alert(data.param);
}, false);

支持Promise

在不支持Promise的时候,返回值为空

let promise = window.applink.invoke("class", "function", params);
promise.then(function(res) {
    //...
}).catch(function(res) {
    //...
})

对外提供的接口

applink.fireEvent

触发H5页面指定事件
参数:

  • @param eventname {String} 事件名
  • @param eventdata {String} 参数

applink.setParam

IOS下设置过多的额外参数
参数:

  • @param uuid
  • @param params {String} 参数字符串

applink.getParam

获得IOS的参数设置
参数:

  • @param uuid

changelog

1.0.0

  1. 完成js对ios和native的调用
  2. 完成Promise

1.1.0

  1. ES6重构代码,改变代码结构
  2. 加入事件监听,方便native调用H5
  3. 可配置协议头信息,超时信息
  4. 优化显示内容

1.1.1

  1. 添加单元测试

1.1.2

  1. 添加param和chunk可以额外存储参数,解决安卓端和ios上回调参数过过长而导致丢失。

待更新问题

  1. 添加对UA的更多侦测,假如指定的UA
  2. 添加hybird.js的封装

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.