Ionic ios 应用程序在 android 上真的很慢但很快

Posted

技术标签:

【中文标题】Ionic ios 应用程序在 android 上真的很慢但很快【英文标题】:Ionic ios app is really slow but fast on android 【发布时间】:2020-12-21 15:54:24 【问题描述】:

我用 ionic 创建了一个应用程序,它几乎完成了(它是一个购物车商店应用程序)。现在我想构建应用程序,我正在使用以下命令:

ionic cordova build --release --prod --verbose XXXXX

其中XXXXXiosandroid

在为 android 构建应用程序时(在签名等之后),应用程序在启动屏幕上需要 3 或 4 秒,这是可以接受的时间,但是当我使用相同的命令为 ios 构建时,问题就出现了,我试图在 XCode 中测试该应用程序并且它可以工作,唯一的问题是该应用程序需要 30 秒,这使该应用程序无法使用,我可以弄清楚原因。

编辑:我也认为问题出在模拟器上,但我也尝试在设备上运行应用程序,结果相同。

下面我会留下信息:

离子信息

Ionic:

   Ionic CLI                     : 6.11.7 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 4.11.10
   @angular-devkit/build-angular : 0.803.29
   @angular-devkit/schematics    : 8.3.29
   @angular/cli                  : 8.3.29
   @ionic/angular-toolkit        : 2.3.2

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 14 other plugins)

Utility:

   cordova-res : 0.15.1
   native-run  : 1.0.0

System:

   ios-deploy : 1.11.1
   ios-sim    : 8.0.2
   NodeJS     : v12.16.1 (/usr/local/bin/node)
   npm        : 6.14.8
   OS         : macOS Catalina
   Xcode      : Xcode 11.7 Build version 11E801a

JSON 包


  "name": "store-app",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": 
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint --typeCheck",
    "e2e": "ng e2e",
    "clean-project": "rm -rf www && rm -rf platforms && rm -rf node_modules && rm -rf plugins"
  ,
  "private": true,
  "dependencies": 
    "@agm/core": "~1.0.0",
    "@angular/common": "^8.2.14",
    "@angular/core": "^8.2.14",
    "@angular/forms": "^8.2.14",
    "@angular/platform-browser": "^8.2.14",
    "@angular/platform-browser-dynamic": "^8.2.14",
    "@angular/router": "^8.2.14",
    "@ionic-native/android-permissions": "^5.27.0",
    "@ionic-native/background-mode": "^5.26.0",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/firebase-analytics": "^5.28.0",
    "@ionic-native/geolocation": "^5.10.0",
    "@ionic-native/header-color": "^5.26.0",
    "@ionic-native/keyboard": "^5.14.0",
    "@ionic-native/location-accuracy": "^5.27.0",
    "@ionic-native/onesignal": "^5.13.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic-native/unique-device-id": "^5.9.0",
    "@ionic/angular": "^4.1.0",
    "@ionic/lab": "^3.1.7",
    "@ngx-translate/core": "^10.0.0",
    "@ngx-translate/http-loader": "^3.0.0",
    "animate.css": "^4.1.0",
    "com.testfairy.cordova-plugin": "^2.25.0",
    "cordova-browser": "6.0.0",
    "cordova-plugin-background-mode": "^0.7.3",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-headercolor": "^1.0.0",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.1.3",
    "cordova-plugin-splashscreen": "^6.0.0",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-uniquedeviceid": "^1.3.2",
    "cordova-plugin-whitelist": "^1.3.4",
    "core-js": "^2.5.4",
    "onesignal-cordova-plugin": "^2.5.2",
    "rxjs": "~6.6.2",
    "zone.js": "~0.9.1"
  ,
  "devDependencies": 
    "@angular-devkit/architect": "~0.800.0",
    "@angular-devkit/build-angular": "~0.803.29",
    "@angular-devkit/core": "~8.3.29",
    "@angular-devkit/schematics": "~8.3.29",
    "@angular/cli": "~8.3.29",
    "@angular/compiler": "~8.2.14",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@ionic/angular-toolkit": "~2.3.2",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~10.14.2",
    "codelyzer": "~5.2.1",
    "cordova-android": "9.0.0",
    "cordova-ios": "^6.1.0",
    "cordova-plugin-advanced-geolocation": "git+https://github.com/esri/cordova-plugin-advanced-geolocation.git",
    "cordova-plugin-android-permissions": "^1.0.2",
    "cordova-plugin-androidx-adapter": "^1.1.1",
    "cordova-plugin-firebase-analytics": "^4.3.1",
    "cordova-plugin-request-location-accuracy": "^2.3.0",
    "cordova-support-android-plugin": "^1.0.2",
    "cordova-support-google-services": "^1.4.1",
    "husky": "~4.2.5",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.4",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "lint-staged": "^10.2.2",
    "node-sass": "^4.13.1",
    "prettier": "^2.0.5",
    "protractor": "~5.4.0",
    "ts-node": "~8.10.2",
    "tslint": "~5.18.0",
    "tslint-config-prettier": "~1.18.0",
    "tslint-etc": "^1.10.1",
    "typescript": "~3.5.3"
  ,
  "description": "An Ionic project",
  "cordova": 
    "plugins": 
      "cordova-plugin-whitelist": ,
      "cordova-plugin-statusbar": ,
      "cordova-plugin-device": ,
      "cordova-plugin-splashscreen": ,
      "cordova-plugin-ionic-webview": 
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      ,
      "cordova-plugin-ionic-keyboard": ,
      "cordova-plugin-uniquedeviceid": ,
      "cordova-plugin-geolocation": ,
      "onesignal-cordova-plugin": ,
      "cordova-plugin-background-mode": ,
      "com.testfairy.cordova-plugin": ,
      "cordova-plugin-advanced-geolocation": ,
      "cordova-plugin-headercolor": ,
      "cordova-plugin-android-permissions": ,
      "cordova-plugin-request-location-accuracy": 
        "PLAY_SERVICES_LOCATION_VERSION": "16.+"
      ,
      "cordova-plugin-firebase-analytics": 
        "FIREBASE_ANALYTICS_COLLECTION_ENABLED": "true"
      ,
      "cordova-plugin-androidx-adapter": 
    ,
    "platforms": [
      "android",
      "browser",
      "ios"
    ]
  


Config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="1" id="com.btd.buggy" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Buggy</name>
    <description>Store App</description>
    <author email="test@test.com" href="https://test-app.com/">Buggy</author>
    <content src="index.html" />
    <access origin="*" />
    <access origin="about:*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <allow-navigation href="*" />
    <allow-navigation href="about:*" />
    <preference name="ScrollEnabled" value="false" />
    <preference name="android-minSdkVersion" value="22" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="30000" />
    <preference name="ShowSplashScreenSpinner" value="false" />
    <preference name="AutoHideSplashScreen" value="false" />
    <preference name="Orientation" value="portrait" />
    <preference name="AndroidXEnabled" value="true" />
    <preference name="GradlePluginGoogleServicesEnabled" value="true" />
    <preference name="GradlePluginGoogleServicesVersion" value="4.2.0" />
    <engine name="android" spec="9.0.0" />
    <platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:usesCleartextTraffic="true" />
        </edit-config>
        <resource-file src="google-services.json" target="app/google-services.json" />
        <allow-intent href="market:*" />
        <preference name="android-targetSdkVersion" value="28" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
        <resource-file src="resources/android/notification/drawable-mdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-mdpi/ic_stat_onesignal_default.png" />
        <resource-file src="resources/android/notification/drawable-hdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-hdpi/ic_stat_onesignal_default.png" />
        <resource-file src="resources/android/notification/drawable-xhdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-xhdpi/ic_stat_onesignal_default.png" />
        <resource-file src="resources/android/notification/drawable-xxhdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-xxhdpi/ic_stat_onesignal_default.png" />
        <resource-file src="resources/android/notification/drawable-xxxhdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-xxxhdpi/ic_stat_onesignal_default.png" />
    </platform>
    <platform name="ios">
        <resource-file src="GoogleService-Info.plist" target="app/GoogleService-Info.plist" />
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <icon  src="resources/ios/icon/icon.png"  />
        <icon  src="resources/ios/icon/icon@2x.png"  />
        <icon  src="resources/ios/icon/icon-40.png"  />
        <icon  src="resources/ios/icon/icon-40@2x.png"  />
        <icon  src="resources/ios/icon/icon-40@3x.png"  />
        <icon  src="resources/ios/icon/icon-50.png"  />
        <icon  src="resources/ios/icon/icon-50@2x.png"  />
        <icon  src="resources/ios/icon/icon-60.png"  />
        <icon  src="resources/ios/icon/icon-60@2x.png"  />
        <icon  src="resources/ios/icon/icon-60@3x.png"  />
        <icon  src="resources/ios/icon/icon-72.png"  />
        <icon  src="resources/ios/icon/icon-72@2x.png"  />
        <icon  src="resources/ios/icon/icon-76.png"  />
        <icon  src="resources/ios/icon/icon-76@2x.png"  />
        <icon  src="resources/ios/icon/icon-83.5@2x.png"  />
        <icon  src="resources/ios/icon/icon-small.png"  />
        <icon  src="resources/ios/icon/icon-small@2x.png"  />
        <icon  src="resources/ios/icon/icon-small@3x.png"  />
        <icon  src="resources/ios/icon/icon-1024.png"  />
        <splash  src="resources/ios/splash/Default-568h@2x~iphone.png"  />
        <splash  src="resources/ios/splash/Default-667h.png"  />
        <splash  src="resources/ios/splash/Default-736h.png"  />
        <splash  src="resources/ios/splash/Default-Landscape-736h.png"  />
        <splash  src="resources/ios/splash/Default-Landscape@2x~ipad.png"  />
        <splash  src="resources/ios/splash/Default-Landscape@~ipadpro.png"  />
        <splash  src="resources/ios/splash/Default-Landscape~ipad.png"  />
        <splash  src="resources/ios/splash/Default-Portrait@2x~ipad.png"  />
        <splash  src="resources/ios/splash/Default-Portrait@~ipadpro.png"  />
        <splash  src="resources/ios/splash/Default-Portrait~ipad.png"  />
        <splash  src="resources/ios/splash/Default@2x~iphone.png"  />
        <splash  src="resources/ios/splash/Default~iphone.png"  />
        <splash  src="resources/ios/splash/Default@2x~universal~anyany.png"  />
        <icon  src="resources/ios/icon/icon-20.png"  />
        <icon  src="resources/ios/icon/icon-20@2x.png"  />
        <icon  src="resources/ios/icon/icon-20@3x.png"  />
        <icon  src="resources/ios/icon/icon-29.png"  />
        <icon  src="resources/ios/icon/icon-29@2x.png"  />
        <icon  src="resources/ios/icon/icon-29@3x.png"  />
        <icon  src="resources/ios/icon/icon-24@2x.png"  />
        <icon  src="resources/ios/icon/icon-27.5@2x.png"  />
        <icon  src="resources/ios/icon/icon-44@2x.png"  />
        <icon  src="resources/ios/icon/icon-86@2x.png"  />
        <icon  src="resources/ios/icon/icon-98@2x.png"  />
        <icon  src="resources/ios/icon/icon-108@2x.png"  />
        <splash  src="resources/ios/splash/Default-2688h~iphone.png"  />
        <splash  src="resources/ios/splash/Default-1792h~iphone.png"  />
        <splash  src="resources/ios/splash/Default-2436h.png"  />
    </platform>
    <platform name="ios">
        <config-file parent="NSLocationAlwaysUsageDescription" platform="ios" target="*-Info.plist">
            <string>Buggy necesita acceder a tu ubicación para poder brindarte un mejor servicio.</string>
        </config-file>
        <config-file parent="NSLocationWhenInUseUsageDescription" platform="ios" target="*-Info.plist">
            <string>Buggy necesita acceder a tu ubicación para poder brindarte un mejor servicio.</string>
        </config-file>
    </platform>
    <plugin name="cordova-plugin-whitelist" spec="1.3.3" />
    <plugin name="cordova-plugin-statusbar" spec="2.4.2" />
    <plugin name="cordova-plugin-device" spec="2.0.2" />
    <plugin name="cordova-plugin-splashscreen" spec="5.0.2" />
    <plugin name="cordova-plugin-ionic-webview" spec="^4.0.0" />
    <plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
    <plugin name="cordova-plugin-advanced-geolocation" spec="https://github.com/esri/cordova-plugin-advanced-geolocation.git" />
    <plugin name="cordova-plugin-uniquedeviceid" spec="1.3.2" />
    <plugin name="onesignal-cordova-plugin" spec="2.5.2" />
</widget>

应用路由模块


@NgModule(
  imports: [
    RouterModule.forRoot(routes, 
      preloadingStrategy: PreloadAllModules,
    ),
  ],
  exports: [RouterModule],
)
export class AppRoutingModule 

其中路线是我的所有路线,我有 38 个视图。

在我的 App 模块中,我也加载了所有服务,但我认为这并不重要,因为 angular 也应该很慢。

感谢您阅读本文。

【问题讨论】:

【参考方案1】:

基本上我发现了问题,之前的app开发者在config.xml留下了以下几行:

<preference name="SplashScreenDelay" value="30000" />
<preference name="ShowSplashScreenSpinner" value="false" />
<preference name="AutoHideSplashScreen" value="false" />

因此在iOS 上隐藏启动画面的功能不起作用,因此删除这些行并添加:

<preference name="AutoHideSplashScreen" value="false" />

让它工作,对我来说唯一奇怪的是Android 上没有这种行为,但现在一切都按预期工作。

【讨论】:

【参考方案2】:

我在两个平台上都有几个应用程序,我可以确认平台之间没有这种差异;性能应该差不多。

我认为您需要在隐藏启动画面之前检查您的代码并查看发生了什么。然后通过删除/添加功能来缩小范围,看看问题出在哪里。

如果您使用 ios 特定插件,这可能是一个原因。此外,某些插件可能需要不同的配置,具体取决于平台。

如果不调试您的代码,就很难说问题出在哪里。我鼓励创建一个空项目并继续添加您的功能以查看瓶颈在哪里。如果我们能确定具体问题,我们可能会帮助解决它,但不知道瓶颈,很难说什么......

无论如何,与您怀疑的实际设备相比,模拟器总是会慢

【讨论】:

以上是关于Ionic ios 应用程序在 android 上真的很慢但很快的主要内容,如果未能解决你的问题,请参考以下文章

android 6 和 IOS 9 中的 Ionic 问题

Ionic 2 fileTransfer.download 在 iOS 上没有反应

Ionic 应用程序在浏览器和 ios 上运行,但不在 android 上,与服务器的连接不成功。 (文件///android_asset/www/index.html)在android上

在 Ionic 中将 Android 和 iOS 原生代码 SDK 暴露给 Javascript

ionic 2 和 iOS10 的 CSP 之争

删除 ionic 3 中的 iOS 滚动反弹