Latest 2.0.1
Homepage https://github.com/TieShanWang/WKJSHandler
License MIT
Platforms ios 8.0
Frameworks UIKit, WebKit
Authors

oc <-> js handler, deal for js call app

<!– 下面是H5 中的代码例子 –!>

window.webkit.messageHandlers.alterInfo.postMessage()

window.webkit.messageHandlers.startApply.postMessage()

如下为一个完整示例

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html>
    <head>
        <meta charset="UTF-8">
        <title>wkWebView</title>

    </head>
    <body>

    <div>
        <button onclick="alertSheet()">弹框 -> alertSheet</button>
        <span id="sheet"></span>
    </div>

    <div>
        <button onclick="showAlert()">弹框 -> alert</button>
        <span id="alert"></span>
    </div>

    <div>
        <button onclick="jumpToBaidu()">新增界面 -> 跳转到百度</button>
    </div>

    <div>
        <button onclick="pageSecond()">新增界面 -> 跳转到第二界面</button>
    </div>

    <div>
        <button onclick="pageSecondInside()">内部跳转 -> 跳转到第二界面</button>
    </div>

    <div>
        <button onclick="Native.enablePullDownRefresh({enable: true})">打开下拉刷新功能</button>
        <button onclick="Native.enablePullDownRefresh({enable: false})">关闭下拉刷新功能</button>
        <button onclick="Native.startPullDownRefresh()">开始下拉刷新</button>
        <button onclick="Native.stopPullDownRefresh()">结束下拉刷新</button>
    </div>

    <div>
        <button onclick="showToast()">show toast</button>
    </div>

    <div>
        <button onclick="Native.showLoading({title: '点完你就后悔了,你会发现啥都做不了了,你要不要重启手机试试'})">show loading</button>
    </div>

    <div>
        <button onclick="Native.hiddenLoading()">hidden loading</button>
    </div>

    <div>
        <button onclick="Native.makePhoneCall({phoneNum: '15003836653'})">打电话</button>
    </div>

    <div>
        <span>当前亮度:</span><span id="getScreenBrightness"></span>
    </div>

    <div>
        <button onclick="Native.setScreenBrightness({value: 1.0})">亮</button>
    </div>

    <div>
        <button onclick="Native.setScreenBrightness({value: 0.2})">暗</button>
    </div>

    <div>
        <button onclick="Native.vibrateShort()">震动</button>
    </div>

    <div>
        <button onclick="Native.setNavigationBarTitle({title: '修改标题'})">更改导航标题</button>
        <button onclick="Native.setNavigationBarTitle({title: '测试'})">还原</button>
    </div>

    <div>
        <button onclick="Native.setNavigationBarColor({frontColor: '#FFFFFF',backgroundColor: '#647cff' })">更改导航颜色</button>
        <button onclick="Native.setNavigationBarColor({frontColor: '#000000',backgroundColor: '#FFFFFF' })">还原</button>
    </div>

    <div>
        <button onclick="weatherTest()">网络测试,检测手机号 15003836653 是否已经注册</button>
        <p id="weather"></p>
    </div>

    <div>
        <button onclick="Native.scrollTo({position: 200})">滚动到200px处</button>
    </div>

    <script type="text/javascript">

        Native.onPullDownRefresh = function(){
            Native.showAlert({
                title: '已经下拉刷新',
                itemList: ['知道了,别比比']
            })
        };

        function weatherTest() {
            Native.request({
                url: "http://dealer-server.shenmajr.com/dealer-server/dealer/checkPhone",
                data: {
                    loginName: '15003836653',
                },
                complete: function ({error, data}) {
                    document.getElementById('weather').innerHTML = JSON.stringify(data)
                }
            })
        }

        function jumpToBaidu() {

            Native.navigateTo({url: 'https://www.baidu.com', success: function () {

            }, fail: function () {

            }})
        }

        function alertSheet() {
            var list = ['第一个', '第二个', '第三个'];
            Native.showActionSheet({
                title: 'hello world',
                message: '不好好学习',
                itemList: list,
                success: function (index) {
                    document.getElementById('sheet').innerHTML = '选择了' + list[parseInt(index)];
                }
            })
        }

        function showAlert() {
            var list = ['第一个', '第二个', '第三个'];
            Native.showAlert({
                title: 'hello world',
                message: '不好好学习',
                itemList: list,
                success: function (index) {
                    document.getElementById('alert').innerHTML = '选择了' + list[parseInt(index)];
                }
            })
        }

        function showToast() {
            Native.showToast({
                title: 'hello title',
                message: '点击下面的按钮试试',
            })
        }

        Native.getScreenBrightness({success: function (light) {
            document.getElementById('getScreenBrightness').innerHTML = light;
        }});

        function pageSecond() {
            var url = window.location.href;
            url = url.replace('wkWebView', 'newWebView');
            Native.navigateTo({
                url: url,
            })
        }

        function pageSecondInside() {
            var url = window.location.href;
            url = url.replace('wkWebView', 'insideNewWebView');
            window.location.href = url;
        }

    </script>
    </body>
</html>

Latest podspec

{
    "name": "WKJSHandler",
    "version": "2.0.1",
    "summary": "swift <-> js handler",
    "description": "oc <-> js handler, deal for js <--> app",
    "homepage": "https://github.com/TieShanWang/WKJSHandler",
    "license": "MIT",
    "authors": {
        "wangtieshan": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/TieShanWang/WKJSHandler.git",
        "tag": "2.0.1"
    },
    "frameworks": [
        "UIKit",
        "WebKit"
    ],
    "source_files": "WKJSHandler/WKJSHandler/**/*.swift",
    "resources": "WKJSHandler/WKJSHandler/injectjs",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This