ionic加载网页失败,错误:操作无法完成.(NSURLErrorDomain错误-999)



当我使用AngularJS并试图在实际设备上使用它时,我得到以下输出:

    2015-07-06 17:00:15.760 MyApp[2195:832165] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///private/var/mobile/Containers/Data/Application/D7596A9C-B658-454C-8418-9A61B26091C2/Library/Cookies/Cookies.binarycookies
    2015-07-06 17:00:15.803 MyApp[2195:832165] Apache Cordova native platform version 3.8.0 is starting.
    2015-07-06 17:00:15.804 MyApp[2195:832165] Multi-tasking -> Device: YES, App: YES
    2015-07-06 17:00:15.811 MyApp[2195:832165] Unlimited access to network resources
    2015-07-06 17:00:16.460 MyApp[2195:832165] Resetting plugins due to page load.
    2015-07-06 17:00:16.911 MyApp[2195:832165] Finished load of: file:///private/var/mobile/Containers/Bundle/Application/47769242-72D0-4907-810A-85332D9564AF/MyApp.app/www/index.html#/home
    2015-07-06 17:00:24.247 MyApp[2195:832165] Resetting plugins due to page load.
    2015-07-06 17:00:24.259 MyApp[2195:832165] Failed to load webpage with error: The operation couldn’t be completed. (NSURLErrorDomain error -999.)
    2015-07-06 17:04:08.907 MyApp[2195:832165] Resetting plugins due to page load.
    2015-07-06 17:04:08.910 MyApp[2195:832165] Failed to load webpage with error: The operation couldn’t be completed. (NSURLErrorDomain error -999.)
    2015-07-06 17:06:19.397 MyApp[2195:832165] Received memory warning. // Here the the app crashes

index.html看起来像:

  <body ng-app="myapp.module">
    <ion-pane ng-controller="HomeCtrl" ng-init="check()">
      <ion-header-bar class="bar-stable">
        <h1 class="title">My ionic app</h1>
      </ion-header-bar>
      <ion-content class="home-content">
        <div class="welcome-message"> Welcome, <span ng-if="!userInfo.isAuthenticated">{{guest}}</span> <span ng-if="userInfo.isAuthenticated">{{userInfo.profile.name}}</span> !</div>
        <button type="button" class="button center-block button-positive" ng-show="userInfo.isAuthenticated" ng-click="logout()" name="button">{{logOutTextButton}}</button>
        <button type="button" class="button center-block button-positive" ng-hide="userInfo.isAuthenticated" ng-click="login()" name="button">{{loginTextButton}}</button>
      </ion-content>
      <footer>Footer text</footer>
    </ion-pane>
  </body>

从错误代码"999",它看起来像你正在加载或重新加载第二个url之前UIWebView完成加载第一个url…

因此,系统取消了第一个url,并试图加载您传递给它的第二个url…

我的Cordova应用程序也出现了同样的错误,花了很多小时才意识到根本原因。

首先,我观察到至少触发了"onDeviceReady"事件(通过在那里放置一个警告语句)。所以我怀疑它可能是任何插件,可能在"onDeviceReady"内抛出错误。我把所有调用插件在单独的try-catch块。这使得"onDeviceReady"成功完成并启动应用程序。最后,我还发现指向一个插件的错误日志。