xcode 离子无法加载网页,错误:无法连接到服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26314005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:00:41  来源:igfitidea点击:

ionic Failed to load webpage with error: Could not connect to the server

xcodecordovaios8ionic-framework

提问by BarakChamo

I'm having an issue with Ionic projects after updating to Xcode 6 and iOS 8.

更新到 Xcode 6 和 iOS 8 后,我遇到了 Ionic 项目的问题。

When trying to run projects I get the following error in Xcode:

尝试运行项目时,我在 Xcode 中收到以下错误:

Failed to load webpage with error: Could not connect to the server.

The full log is:

完整的日志是:

2014-10-11 14:08:29.468 test[23293:109668] Apache Cordova native platform version 3.6.3 is starting.
2014-10-11 14:08:29.469 test[23293:109668] Multi-tasking -> Device: YES, App: YES
2014-10-11 14:08:29.495 test[23293:109668] Unlimited access to network resources
2014-10-11 14:08:29.866 test[23293:109668] [CDVTimer][keyboard] 0.079989ms
2014-10-11 14:08:29.866 test[23293:109668] [CDVTimer][TotalPluginStartup] 0.284970ms
2014-10-11 14:08:30.721 test[23293:109668] Resetting plugins due to page load.
2014-10-11 14:08:30.764 test[23293:109668] Failed to load webpage with error: Could not connect to the server.

Even when trying to update Ionic and Cordova and starting a new project this error keeps popping up.

即使在尝试更新 Ionic 和 Cordova 并开始新项目时,此错误也会不断弹出。

I couldn't find any threads with this particular error and I'm not sure if this is an iOS 8 compatibility issue or something is messed up with my setup.

我找不到任何带有此特定错误的线程,我不确定这是 iOS 8 兼容性问题还是我的设置有问题。

Thanks!

谢谢!

EDIT:

编辑:

A bit more info on what's in the index.html and app.js

关于 index.html 和 app.js 内容的更多信息

index.html:

索引.html:

<!DOCTYPE html>
<html ng-app="app" ng-controller="AppCtrl">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <!-- compiled CSS -->
    <link rel="stylesheet" type="text/css" href="assets/app-0.0.1.css" />

    <!-- compiled JavaScript -->
    <script type="text/javascript" src="src/app/app.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>
  </head>
  <body >
    <ion-nav-view></ion-nav-view>


    <!-- Load deferred scripts -->

    <!-- Google Maps -->
    <script src='http://maps.googleapis.com/maps/api/js?sensor=true&callback=googleMapsLoaded' defer async></script>
  </body>
</html>

and app.js (before compilation with the rest of the files using ngbp):

和 app.js(在使用 ngbp 与其余文件编译之前):

angular.module( 'app', [
  'ionic',

  // Common requirements
  'templates-app',
  'templates-common',

  // Common Components
  'app.auth',

  // All page modules
  'app.businesses',
  'app.business',
  'app.search',
  'app.branch',
  'app.profile',
  'app.feed',

  // Other dependencies
  'ui.router'
])

.config(['$stateProvider', '$urlRouterProvider', function myAppConfig ($stateProvider, $urlRouterProvider) {
  $stateProvider
  .state('app', {
    url: "/app",
    abstract: true,
    templateUrl: "menu/menu.tpl.html",
    controller: 'AppCtrl'
  });

  $urlRouterProvider.otherwise( 'app/feed' );
}])

.run(['$ionicPlatform', 'appAuthService', '$sessionStorage', function($ionicPlatform, appAuthService, $sessionStorage) {
  // Initialize ionic styles
  $ionicPlatform.ready(function() {
    if(window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
      StatusBar.styleLightContent();
    }
  });

  // Initialize app authentication service
  appAuthService.init();

  // Initialize a session cache validation object
  $sessionStorage.updated = {};
}])

.controller( 'AppCtrl', ['$scope', '$location', function AppCtrl ($scope, $location) {

}])

;

回答by tobika

I had the same problem.

我有同样的问题。

I opened the ios project in the platform folder via Xcode, but I forgot that the codebase in the Xcode folder was not up to date and therefore broken.

我通过Xcode打开了平台文件夹中的ios项目,但我忘记了Xcode文件夹中的代码库不是最新的,因此被破坏了。

To get the new code in your Xcode project use the command:

要在 Xcode 项目中获取新代码,请使用以下命令:

ionic cordova prepare ios

If your problem is rooted in the same as mine this should help.

如果您的问题与我的问题根源相同,那么这应该会有所帮助。

回答by Future2020

This error may also occur if you open the project using Xcode after used the live debugging with the emulator

如果您在使用模拟器实时调试后使用 Xcode 打开项目,也可能会出现此错误

ionic cordova emulate ios --livereload -lc

离子科尔多瓦模拟 ios --livereload -lc

To solve the issue, close Xcode and build the project again using

要解决此问题,请关闭 Xcode 并使用

ionic cordova build ios

Then build and run using Xcode.

然后使用 Xcode 构建并运行。

回答by Laurens

I encountered this issue when I tried to run my Ionic 4 app on an iOS device.

当我尝试在 iOS 设备上运行我的 Ionic 4 应用程序时,我遇到了这个问题。

What solved it for me, was running the dev server on all network interfaces using the --addressoption, for example:

为我解决的问题是使用该--address选项在所有网络接口上运行开发服务器,例如:

ionic cordova run ios --address=0.0.0.0 --debug --consolelogs -l

ionic cordova run ios --address=0.0.0.0 --debug --consolelogs -l

回答by ssomu

I have run the server and simulator and again am trying to update the app on the device.

我已经运行了服务器和模拟器,并再次尝试更新设备上的应用程序。

Then I had the same problem

然后我遇到了同样的问题

I stoped my simulator and re builded the app and opened the project.xcodeproj file with Xcode and run it on the device.This worked for me

我停止了我的模拟器并重新构建了应用程序并使用 Xcode 打开了 project.xcodeproj 文件并在设备上运行它。这对我有用

回答by omadoye abraham

I had this same issue using XCode9.3 and ionic3. Turns out that the issue was caused by missing configurations in "config.xml" needed for WKWebview to function properly. I added the following snippet to my config.xml, before deleting the "platforms/ios" folder and running "ionic cordova build ios --prod" again.

我在使用 XCode9.3 和 ionic3 时遇到了同样的问题。事实证明,该问题是由于 WKWebview 正常运行所需的“config.xml”中缺少配置造成的。在删除“platforms/ios”文件夹并再次运行“ionic cordova build ios --prod”之前,我将以下代码段添加到我的 config.xml 中。

 <allow-navigation href="http://localhost:8080/*" />
    <feature name="CDVWKWebViewEngine">
        <param name="ios-package" value="CDVWKWebViewEngine" />
    </feature>
    <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />

See link herefor a more detailed explanation from the ionic team.

有关离子团队的更详细解释,请参见此处链接

回答by Gleb Mikheev

I found a solution, i hope it helps: https://github.com/glebmachine/cordova-plugin-ionic/commit/7c095a45a13f7349e93f14a3057153775109f635

我找到了一个解决方案,希望对您有所帮助:https: //github.com/glebmachine/cordova-plugin-ionic/commit/7c095a45a13f7349e93f14a3057153775109f635

To install from my fork: cordova plugin add https://github.com/glebmachine/cordova-plugin-ionic.git#v4

从我的叉子安装: cordova plugin add https://github.com/glebmachine/cordova-plugin-ionic.git#v4