美文网首页
construct2 问题 整理

construct2 问题 整理

作者: squidbrother | 来源:发表于2019-10-14 11:52 被阅读0次
    audio加载 方法 兼容性问题

    表现:
    在PC端支持 reload 音频事件,会触发 all audio reload
    在IPHONE 微信浏览器上,不会触发此行为

    C2与web通信

    1.C2与导出的htm5
    借助Browser模块,可以通过execute javascript调用 导出后html页面中 自定义的javascript函数
    C2 主动调用导出后 html5中方法 (可行)

    2.C2与同域接口
    通过AJAX模块 (可行)

    3.C2被其他框架调用
    但是如果C2要提供给html中调用方法,由html页面来主动调用,就不能操作

    比如:
    C2导出html5后,嵌入到IOS APP的webview中,如果调用了APP的支付(异步操作)成功后,向C2游戏中添加金币操作
    目前没有找到好的方法,后续希望通过浏览器作为媒介中转来通信

    尝试:localstorage
    但是localstorage在不同浏览器下,表现不太一样 如 (chrome与firefox)
    google使用indexDB存储数据,firefox使用localstorage 所以无法统一

    后续陆续尝试...
    发现hash操作,浏览器表现相对统一,所以借助hash操作,来完成这个支付操作

    具体实现流程:


    APP与html5 hash通信

    html5部分脚本

    function setupWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) {
            return callback(WebViewJavascriptBridge);
        }
        if (window.WVJBCallbacks) {
            return window.WVJBCallbacks.push(callback);
        }
        window.WVJBCallbacks = [callback];
        var WVJBIframe = document.createElement('iframe');
        WVJBIframe.style.display = 'none';
        WVJBIframe.src = 'https://__bridge_loaded__';
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function() {
            document.documentElement.removeChild(WVJBIframe)
        },
        0)
    }
    
    function buyGoods() {
        setupWebViewJavascriptBridge(function(bridge) {
            bridge.callHandler('ZJPurchase', {
                'data': 'gold'
            },
            function(res) {
                if (res != null) {
                    window.location.hash = "#faildeel";
                    return;
                }
    
                window.location.hash = "#deelit";
            })
        })
    }
    
    function callmoneyfn() {
        buyGoods();
    }
    
    function clearmyhash() {
        window.location.hash = "";
    }
    

    相关文章

      网友评论

          本文标题:construct2 问题 整理

          本文链接:https://www.haomeiwen.com/subject/xaxrmctx.html