




#ifndef ACJSConstant_h
#define ACJSConstant_h

// js处理native调用
static const NSString *kACJSHandleMessageFormat = @"window.AppCoreJS._handleMessageFromNative(%@);";

// openNativeURL 以url方式调用native 接口类型，对象名，方法名，参数
static const NSString* kACJSInjectBasic = @"\
var messageQuery = new Map();\
var uniqueId = 1;\
window.AppCoreJS = {\
requestNative : function(interface, obj, funcName, data, responseCallback) {\
    var message = {};\
    message.obj = obj;\
    message.data = data;\
    if (!!responseCallback) {\
        var callbackId ='cb_'+ (uniqueId++) + '_' + new Date().getTime();\
        message.callbackId = callbackId;\
        message.responseCallback = responseCallback;\
        messageQuery.set(callbackId,message);\
    }\
    window.AppCoreJS.openNativeURL(interface,obj,funcName,JSON.stringify(message));\
},\
openNativeURL : function (interface, obj, functionName, args) {\
    var formattedArgs = (args.length > 0 ? encodeURIComponent(args):\"\");\
    var iframe = document.createElement(\"IFRAME\");\
    iframe.setAttribute(\"src\", interface + \":\" + obj + \":\" + encodeURIComponent(functionName) +\":\" + formattedArgs);\
    document.documentElement.appendChild(iframe);\
    iframe.parentNode.removeChild(iframe);\
    iframe = null;\
},\
_handleMessageFromNative : function(nativeMessage) {\
    setTimeout(function() {\
    var message;\
    if(nativeMessage.callbackId){\
    message = messageQuery.get(nativeMessage.callbackId);\
    console.log(nativeMessage.responseData);\
    if (!message||(!message.responseCallback)) {\
    return;\
    }\
    message.responseCallback(nativeMessage.responseData);\
    messageQuery.delete(message.callbackId);\
    }\
    },0)\
},\
funcConvertInject: function (plus, interface, obj, methods) {\
    window[plus] = {};\
    var jsPlus = window[plus];\
    for (var i = 0, l = methods.length; i < l; i++){\
        (function () {\
            var method = methods[i];\
            var jsMethod = method.replace(new RegExp(\":\", \"g\"), \"\");\
            jsPlus[jsMethod] = function (data,responseCallback) {\
                window.AppCoreJS.requestNative(interface, obj, jsMethod, data,responseCallback);\
            };\
        })();\
    }\
},\
}\
";

#endif
