如何为使用PhoneGap Build构建的PhoneGap项目请求权限?

时间:2019-07-14 20:40:49

标签: phonegap-build phonegap

我正在尝试使用Phonegap和Phonegap Build来创建基于html / jquery的Android应用。当前,我的应用程序由一个HTML页面组成,您可以输入两个数字,这些数字将发送到我的服务器,并且响应会显示在屏幕上。这是代码:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
            <title>PoC</title>
            <script src="JS/jquery.min.js"></script>
            <script src="JS/jquery-ui.min.js"></script>
            <script language="javascript" src="JS/date.js"></script>
            <link rel="stylesheet" type="text/css" media="all" href="css/style.css">

            <script>
                function doCalc() {
                    $.ajax({
                        url: "http://nightscapecreations.com/test.cfc?method=multNums&thisNum=" + $('#thisNum').val() + "&multBy=" + $('#multBy').val()
                    }).done(function( data ) {
                        data    = data.trim();
                        if ($.isNumeric(data)) {
                            $('#resultDiv').html(data); 
                        } else {
                            $('#resultDiv').html(data);
                        }
                    })
                }
            </script>
        </head>
        <body>
            <script type="text/javascript" src="cordova.js"></script>
            This is a test.  Here, multiply some numbers:

            <input id="thisNum" placeholder="5" onChange="doCalc();"> x
            <input id="multBy" placeholder="3" onChange="doCalc();">
            =
            <div id="resultDiv">

            </div>

            <input type="button" value="Calculate" onClick="doCalc();" style="width:150px;">
        </body>
    </html>

只是一个非常混乱的测试,以了解整个过程如何工作。在浏览器中打开或通过Phonegap应用程序运行时,此功能起作用。但是,当我将其上传到Phonegap Build,下载apk,将其复制到设备并安装到设备上时,div无法填充。

我看着我的应用程序,很惊讶地看到它没有权限列出。我怀疑这是失败的原因;该应用无法访问互联网,因此无法从其Ajax调用中获得响应。这也可以解释为什么PB的Weinre调试没有显示目标。但是,无论如何我都无法弄清楚如何让PB分配权限。

这是我当前的配置:

    <?xml version='1.0' encoding='utf-8'?>
    <widget id="com.nightscapecreations.test"
            version="1.0.0"
            xmlns="http://www.w3.org/ns/widgets"
            xmlns:gap="http://phonegap.com/ns/1.0">
        <name>Test</name>
        <description>
            A PoC app
        </description>
        <author email="xxxxxxxxxxxx@hotmail.com" href="http://phonegap.com">
            My Name
        </author>
        <content src="index.html" />

        <access origin="*" />
        <allow-intent href="http://*/*" />
        <allow-intent href="https://*/*" />
        <allow-intent href="tel:*" />
        <allow-intent href="sms:*" />
        <allow-intent href="mailto:*" />
        <allow-intent href="geo:*" />
        <platform name="android">
          <allow-intent href="market:*" />
        </platform>
        <platform name="ios">
          <allow-intent href="itms:*" />
          <allow-intent href="itms-apps:*" />
        </platform>

        <preference name="orientation" value="portrait"/>
        <preference name="fullscreen" value="false"/>
        <preference name="permissions" value="none"/>
        <feature name="http://api.phonegap.com/1.0/network"/>
        <plugin name="cordova-plugin-network-information" source="npm" spec="~1.2.0" />
    </widget>

里面有很多东西,因为我经历了无数次反复的试验和错误,这些反复遍历了来自SO和各种博客的内容。我尝试过是否使用首选项标签,功能标签,插件标签等,但该应用程序从未请求过权限。

我还尝试按照另一篇文章中的建议添加安全策略,但没有成功:

    <meta http-equiv="Content-Security-Policy" 
      content="default-src *; 
               style-src 'self' 'unsafe-inline' 'unsafe-eval'; 
               script-src 'self' 'unsafe-inline' 'unsafe-eval';">

如何确保我的应用程序具有足够的特权来从服务器获取数据?

0 个答案:

没有答案