PhoneGap的和提示() [英] Phonegap and prompt()

查看:135
本文介绍了PhoneGap的和提示()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PhoneGap 来源为Android翻翻,并试图验证其 notification.alert( )方法只是委托给本地JavaScript 警报()功能。他们的code的作用:

I was looking through the Phonegap sources for Android, and trying to verify that their notification.alert() method simply delegates to the native JavaScript alert() function. Their code does:

Notification.prototype.alert = function(message, completeCallback, title, buttonLabel) {
    var _title = (title || "Alert");
    var _buttonLabel = (buttonLabel || "OK");
    PhoneGap.exec(completeCallback, null, "Notification", "alert", [message,_title,_buttonLabel]);
};

这看起来对我来说,通知将PTED作为函数的名称来调用执行exec(),而 EXEC()是这样做的:

PhoneGap.exec = function(success, fail, service, action, args) {
    try {
        var callbackId = service + PhoneGap.callbackId++;
        if (success || fail) {
            PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
        }

        //using:  ["Notification", "alert", callbackId, true]
        var r = prompt(PhoneGap.stringify(args), 
                       "gap:"+PhoneGap.stringify([service, action, callbackId, true]));

        //...
    } catch (e2) {
        console.log("Error: "+e2);
    }
}; 

现在 PhoneGap.stringify()简单解析为 JSON.stringify(),这样的PhoneGap code是通过调用两个JSON对象/数组的提示符()函数执行 notification.alert() API方法。我的假设是,提示符()本地JavaScript提示()函数(我还没有发现任何东西在自己的JavaScript code,将重写此功能)。如果是这样的话,那么这是怎么code工作?

Now PhoneGap.stringify() simply resolves to JSON.stringify(), so the Phonegap code is executing the notification.alert() API method by calling the prompt() function with two JSON objects/arrays. My assumption is that prompt() is the native JavaScript prompt() function (I've not found anything in their JavaScript code that would override this function). If that is the case, then how is this code working?

他们做类似用途提示符()在其他地方,还有:

They make similar use of prompt() in various other places, as well:

PhoneGap.JSCallbackPort = prompt("getPort", "gap_callbackServer:"); 

有没有什么特别的,他们正在呼叫的方式提示符()(特别是通过包括形式间隙的第二个参数。* :. * ),它使一些自定义的行为?还是他们以某种方式覆盖了提示符()函数的默认行为的地方来自于外部的JavaScript code?

Is there something special about the way they are calling prompt() (specifically by including a second parameter of the form gap.*:.*) that is enabling some custom behavior? Or have they somehow overridden the default behavior of the prompt() function somewhere external to their JavaScript code?

请注意,这特别适用于PhoneGap的Andr​​oid版本,其他版本都支持使用略有不同的机制来执行API调用。

Note that this applies specifically to the Android version of Phonegap, as other versions seem to use slightly different mechanisms for executing the API calls.

推荐答案

提示符()功能已被覆盖。

您可以发现,在DroidGap.java。

You can find that in DroidGap.java.

@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
......
}

这篇关于PhoneGap的和提示()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆