构建phonegap项目后,Parse调用不起作用

时间:2015-11-20 07:06:00

标签: android cordova parse-platform phonegap-build

我有一个phonegap项目。它有一个登录页面。我使用parse.com作为后端。当我在我的Android手机上的phonegap应用程序上测试它时它工作得很完美。但是当我构建相同的项目来获取apk时。

signin函数返回XMLHttpRequest失败:{},错误代码为100。

以前关于同一问题的帖子建议在我的html页面中重新排序导入。我不认为这有助于我的情况。

这是我的html头

    <head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <!-- <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" /> -->
    <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.4.5.css">
<script type="text/javascript" src="js/parse-1.6.7.min.js"></script>
    <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>

    <script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script>



     <script type="text/javascript" src="cordova.js"></script> 
    <script type="text/javascript" src='js/gmaps.js'></script>
    <script type="text/javascript" src="js/locationpicker.jquery.js"></script>
    <script type="text/javascript" src="js/index.js"></script>



</head>

这是我的config.xml

    <widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.phonegap.helloworld" version="1.0.0">
  <name>GetItDone</name>
  <description>Hello World sample application that responds to the deviceready event.</description>
  <author href="http://phonegap.com" email="support@phonegap.com">PhoneGap Team</author>
  <content src="index.html"/>
  <preference name="permissions" value="none"/>
  <preference name="orientation" value="default"/>
  <preference name="target-device" value="universal"/>
  <preference name="fullscreen" value="true"/>
  <preference name="webviewbounce" value="true"/>
  <preference name="prerendered-icon" value="true"/>
  <preference name="stay-in-webview" value="false"/>
  <preference name="ios-statusbarstyle" value="black-opaque"/>
  <preference name="detect-data-types" value="true"/>
  <preference name="exit-on-suspend" value="false"/>
  <preference name="show-splash-screen-spinner" value="true"/>
  <preference name="auto-hide-splash-screen" value="true"/>
  <preference name="disable-cursor" value="false"/>
  <preference name="android-minSdkVersion" value="14"/>
  <preference name="android-installLocation" value="auto"/>
  <gap:plugin name="org.apache.cordova.battery-status"/>
  <gap:plugin name="org.apache.cordova.camera"/>
  <gap:plugin name="org.apache.cordova.media-capture"/>
  <gap:plugin name="org.apache.cordova.console"/>
  <gap:plugin name="org.apache.cordova.contacts"/>
  <gap:plugin name="org.apache.cordova.device"/>
  <gap:plugin name="org.apache.cordova.device-motion"/>
  <gap:plugin name="org.apache.cordova.device-orientation"/>
  <gap:plugin name="org.apache.cordova.dialogs"/>
  <gap:plugin name="org.apache.cordova.file"/>
  <gap:plugin name="org.apache.cordova.file-transfer"/>
  <gap:plugin name="org.apache.cordova.geolocation"/>
  <gap:plugin name="org.apache.cordova.globalization"/>
  <gap:plugin name="org.apache.cordova.inappbrowser"/>
  <gap:plugin name="org.apache.cordova.media"/>
  <gap:plugin name="org.apache.cordova.network-information"/>
  <gap:plugin name="org.apache.cordova.splashscreen"/>
  <gap:plugin name="org.apache.cordova.vibration"/>
  <icon src="icon.png"/>
  <icon src="www/res/icon/android/icon-36-ldpi.png" gap:platform="android" gap:qualifier="ldpi"/>
  <icon src="www/res/icon/android/icon-48-mdpi.png" gap:platform="android" gap:qualifier="mdpi"/>
  <icon src="www/res/icon/android/icon-72-hdpi.png" gap:platform="android" gap:qualifier="hdpi"/>
  <icon src="www/res/icon/android/icon-96-xhdpi.png" gap:platform="android" gap:qualifier="xhdpi"/>
  <icon src="www/res/icon/blackberry/icon-80.png" gap:platform="blackberry"/>
  <icon src="www/res/icon/blackberry/icon-80.png" gap:platform="blackberry" gap:state="hover"/>
  <icon src="www/res/icon/ios/icon-57.png" gap:platform="ios" width="57" height="57"/>
  <icon src="www/res/icon/ios/icon-72.png" gap:platform="ios" width="72" height="72"/>
  <icon src="www/res/icon/ios/icon-57-2x.png" gap:platform="ios" width="114" height="114"/>
  <icon src="www/res/icon/ios/icon-72-2x.png" gap:platform="ios" width="144" height="144"/>
  <icon src="www/res/icon/webos/icon-64.png" gap:platform="webos"/>
  <icon src="www/res/icon/windows-phone/icon-48.png" gap:platform="winphone"/>
  <icon src="www/res/icon/windows-phone/icon-173-tile.png" gap:platform="winphone" gap:role="background"/>
  <gap:splash src="www/res/screen/android/screen-ldpi-portrait.png" gap:platform="android" gap:qualifier="port-ldpi"/>
  <gap:splash src="www/res/screen/android/screen-mdpi-portrait.png" gap:platform="android" gap:qualifier="port-mdpi"/>
  <gap:splash src="www/res/screen/android/screen-hdpi-portrait.png" gap:platform="android" gap:qualifier="port-hdpi"/>
  <gap:splash src="www/res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:qualifier="port-xhdpi"/>
  <gap:splash src="www/res/screen/blackberry/screen-225.png" gap:platform="blackberry"/>
  <gap:splash src="www/res/screen/ios/screen-iphone-portrait.png" gap:platform="ios" width="320" height="480"/>
  <gap:splash src="www/res/screen/ios/screen-iphone-portrait-2x.png" gap:platform="ios" width="640" height="960"/>
  <gap:splash src="www/res/screen/ios/screen-iphone-portrait-568h-2x.png" gap:platform="ios" width="640" height="1136"/>
  <gap:splash src="www/res/screen/ios/screen-ipad-portrait.png" gap:platform="ios" width="768" height="1024"/>
  <gap:splash src="www/res/screen/ios/screen-ipad-landscape.png" gap:platform="ios" width="1024" height="768"/>
  <gap:splash src="www/res/screen/windows-phone/screen-portrait.jpg" gap:platform="winphone"/>
  <access origin="*"/>
  <plugin name="cordova-plugin-whitelist" version="1"/>
  <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>
</widget>

我该如何解决这个问题?

更新:

来自chrome远程调试的日志:

    POST https://api.parse.com/1/login 404 (Not Found)
c @ parse-1.6.7.min.js:15
y.ajax @ parse-1.6.7.min.js:15
(anonymous function) @ parse-1.6.7.min.js:15
s @ parse-1.6.7.min.js:14
(anonymous function) @ parse-1.6.7.min.js:14
i @ parse-1.6.7.min.js:14
n.value @ parse-1.6.7.min.js:14
y.request @ parse-1.6.7.min.js:15
T.logIn @ parse-1.6.7.min.js:15
s.value @ parse-1.6.7.min.js:15
s.value @ parse-1.6.7.min.js:15
(anonymous function) @ index.js:173
n.event.dispatch @ jquery-2.1.4.min.js:3
r.handle @ jquery-2.1.4.min.js:3


parse-1.6.7.min.js:15 XHR finished loading: POSThttps://api.parse.com/1/login".
c @ parse-1.6.7.min.js:15
y.ajax @ parse-1.6.7.min.js:15
(anonymous function) @ parse-1.6.7.min.js:15
s @ parse-1.6.7.min.js:14
(anonymous function) @ parse-1.6.7.min.js:14
i @ parse-1.6.7.min.js:14
n.value @ parse-1.6.7.min.js:14
y.request @ parse-1.6.7.min.js:15
T.logIn @ parse-1.6.7.min.js:15
s.value @ parse-1.6.7.min.js:15
s.value @ parse-1.6.7.min.js:15
(anonymous function) @ index.js:173
n.event.dispatch @ jquery-2.1.4.min.js:3
r.handle @ jquery-2.1.4.min.js:3

1 个答案:

答案 0 :(得分:1)

@ 55597, 您尚未正确应用whitelist系统。

阅读:HOW TO apply the Cordova/Phonegap the whitelist system

要解决您的问题,您需要同时应用<allow-navigate (..)>CSP

如果您在没有网页的情况下拨打电话,则<allow-intent (...)>就是您想要的。

如果您通过网页拨打电话,则<allow-navigate (...)>CSP可以拨打电话。这是一个复杂的系统。我没有写。

以下是您需要添加的代码

  1. 添加到config.xml注意:以下将使您的应用程序不安全 <allow-navigation href="*" /> <allow-intent href="*" /> <access origin="*" /> <!-- Required for iOS9 -->
  2. 添加到index.html注意:以下将使您的应用程序不安全 <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src 'self' 'unsafe-inline' 'unsafe-eval';">
  3. 要保护您的代码,请阅读:
    HOW TO apply the Cordova/Phonegap the whitelist system

    此常见问题解答也应该有所帮助 Top Mistakes by Developers new to Cordova/Phonegap
    最好的运气