phoneGap 3.5.0 到 6.5.0 并且 api 状态未定义

Posted

技术标签:

【中文标题】phoneGap 3.5.0 到 6.5.0 并且 api 状态未定义【英文标题】:phoneGap 3.5.0 to 6.5.0 and api status was undifined 【发布时间】:2018-03-29 06:54:34 【问题描述】:

我尝试将我的应用从 3.5.0 更新到 6.5.0 当我用 chrome 打开它时是 200 并且都是和平的 它在 3.5.0 时有效 android 4.4.2 和 5.0.1 上的 api 状态未定义 但在 7.0.0 中为 0,并且没有数据进入。 我要使用的设备是 4.4.2 QQ怎么才能成功获取数据

这是我的 Service.js 之一

 vm.getList = function () 
                alert(url);
                //var Json = [];
                return $http.get(url).then(function (response) alert(response.status);
                    //$rootScope.data.menuList = response;
                    return response;
                , function(err)
                    alert(err.status);
                );

                //return Json.Promise;
            ;

还有我的 config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="tw.nutc.sample" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>MyApp(1005)</name>
    <description>
        HelloWorld
    </description>
    <author href="#" email="#">
        ?????   </author>
    <content src="index.html" />
<preference name="phonegap-version" value="cli-7.0.1" />
<preference name="android-installLocation" value="auto" />
<preference name="android-build-tool" value="gradle" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="14" />
    <plugin name="cordova-plugin-battery-status" source="npm" spec="~1.2.4" />
    <plugin name="cordova-plugin-camera" source="npm" spec="~2.4.1" />
    <plugin name="cordova-plugin-media-capture" source="npm" spec="~1.4.3" />
    <plugin name="cordova-plugin-device" source="npm" spec="~1.1.6" />
    <plugin name="cordova-plugin-dialogs" source="npm" spec="~1.3.3" />
    <plugin name="cordova-plugin-file" source="npm" spec="~4.3.3" />
    <plugin name="cordova-plugin-geolocation" source="npm" spec="~2.4.3" />
    <plugin name="cordova-plugin-globalization" source="npm" spec="~1.0.7" />
    <plugin name="cordova-plugin-inappbrowser" source="npm" spec="~1.7.1" />
    <plugin name="cordova-plugin-network-information" source="npm" spec="~1.3.3" />
    <plugin name="cordova-plugin-vibration" source="npm" spec="~2.1.5" />
    <platform name="android">
        <icon density="ldpi" src="www/res/icon/android/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="www/res/icon/android/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="www/res/icon/android/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="www/res/icon/android/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="www/res/icon/android/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="www/res/icon/android/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="www/res/screen/android/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="www/res/screen/android/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="www/res/screen/android/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="www/res/screen/android/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="www/res/screen/android/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="www/res/screen/android/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="www/res/screen/android/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="www/res/screen/android/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="www/res/screen/android/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="www/res/screen/android/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="www/res/screen/android/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="www/res/screen/android/drawable-port-xxxhdpi-screen.png" />
    </platform>
    <platform name="ios">
        <icon  platform="ios" src="www/res/icon/ios/icon.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon@2x.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-40.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-40@2x.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-50.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-50@2x.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-60.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-60@2x.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-60@3x.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-72.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-72@2x.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-76.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-76@2x.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-small.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-small@2x.png"  />
        <icon  platform="ios" src="www/res/icon/ios/icon-small@3x.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default-568h@2x~iphone.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default-667h.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default-736h.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default-Landscape-736h.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default-Landscape@2x~ipad.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default-Landscape~ipad.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default-Portrait@2x~ipad.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default-Portrait~ipad.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default@2x~iphone.png"  />
        <splash  platform="ios" src="www/res/screen/ios/Default~iphone.png"  />
    </platform>
    <platform name="wp8">
        <icon  platform="wp8" src="www/res/icon/wp8/ApplicationIcon.png"  />
        <icon  platform="wp8" src="www/res/icon/wp8/Background.png"  />
        <splash  platform="wp8" src="www/res/screen/wp8/screen-portrait.jpg"  />
    </platform>
    <platform name="windows">
        <icon  platform="windows" src="www/res/icon/windows/Square150x150Logo.scale-100.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Square30x30Logo.scale-100.png"  />
        <icon  platform="windows" src="www/res/icon/windows/StoreLogo.scale-100.png"  />
        <splash  platform="windows" src="www/res/screen/windows/SplashScreen.scale-100.png"  />
        <icon  platform="windows" src="www/res/icon/windows/StoreLogo.scale-240.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Square44x44Logo.scale-100.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Square44x44Logo.scale-240.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Square70x70Logo.scale-100.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Square71x71Logo.scale-100.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Square71x71Logo.scale-240.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Square150x150Logo.scale-240.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Square310x310Logo.scale-100.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Wide310x150Logo.scale-100.png"  />
        <icon  platform="windows" src="www/res/icon/windows/Wide310x150Logo.scale-240.png"  />
        <splash  platform="windows" src="www/res/screen/windows/SplashScreenPhone.scale-240.png"  />
    </platform>
    <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>
</widget>

感谢QQ

【问题讨论】:

你在哪里传递url作为参数? var url = '192.168.0.100/api/FoodApi' - 这里是 【参考方案1】:

我在您的 config.xml 中没有看到白名单插件。

现在需要白名单插件来允许您的应用访问不在应用内的页面。

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/

为了让您的应用能够在 android 4.4 或更高版本上运行,您可能还需要在 html 中配置 Content-Security-Policy。 (也在白名单插件文档中解释过)。

【讨论】:

【参考方案2】:

配置添加

<allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />
    <allow-navigation href="data:*" />
<plugin name="cordova-plugin-whitelist" spec="~1.2.2" />
    <gap:plugin name="cordova-plugin-whitelist" source="npm" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" /> 

和html添加

<meta charset="utf-8">
    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

response.status 变成 200,谢谢

【讨论】:

以上是关于phoneGap 3.5.0 到 6.5.0 并且 api 状态未定义的主要内容,如果未能解决你的问题,请参考以下文章

ionic 和 phonegap 构建(3.5.0)不显示自定义启动画面

Phonegap (NOT Cordova) 3.5 示例应用程序未启动 deviceready

Urban Airship phonegap 3.5 with Phonegap Build

PhoneGap config.xml - 添加插件不起作用

Cordova 6.5.0 创建 Phone项目

Phonegap构建相机不工作