ios - 如何设置默认设备以在 Ionic 中进行模拟?

标签 ios angularjs cordova ionic-framework emulation

我正在使用 Ionic 构建一个 iOS 应用程序。现在我正在测试它在 iPad 2 中的表现,但是这样做需要我不断地写:

ionic emulate ios --target="iPad-2"

有没有办法在 ionic.project 文件中的某个地方或其他地方对此进行硬编码,以便我可以停止手动执行此操作?谢谢

最佳答案

我遇到了同样的问题,尽管这个问题已经有一年了,但这是我通过谷歌得到的第一件事,在其他任何地方都找不到答案。这就是我所做的只是因为我不想每次都使用 --target="iPhone-7"。

对于任何想要在特定 ios 设备上运行的人来说,请使用以下内容:

ionic run ios --target="iXXX-X"

iXXX-X 将是您从运行中获得的名称之一
ios-sim showdevicetypes例如:
ionic run ios --target="iPhone-7"

我想有一个解决方案使 iPhone-7 成为我的默认目标,因此运行以下命令将针对 iPhone-7(我最初的默认目标是 iPhone-SE):
ionic run ios

似乎默认值是硬编码的,因此必须在代码中进行更改。
我找到了这个文件:/platforms/ios/cordova/lib/run.js

在那里你会找到一个名为 deployToSim 的函数,我对它进行了如下更改:

function deployToSim(appPath, target) {
  // Select target device for emulator. Default is 'iPhone-6'
  if (!target) {
    return require('./list-emulator-images').run()
      .then(function(emulators) {
        if (emulators.length > 0) {
          target = emulators[0];
        }
        emulators.forEach(function(emulator) {
          // this is the original condition
          // if (emulator.indexOf('iPhone') === 0)  
          // change "iPhone" to the specific model you want, in my case it's iPhone-7
          // Notice the comma in iPhone7, without comma it will take iPhone-7-plus instead
          if (emulator.indexOf('iPhone-7,') === 0) {
            target = emulator;
          }
        });
        events.emit('log', 'No target specified for emulator. Deploying to ' + target + ' simulator');
        return startSim(appPath, target);
      });
  } else {
    return startSim(appPath, target);
  }
}

关于ios - 如何设置默认设备以在 Ionic 中进行模拟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35296187/

相关文章:

javascript - $resource 回调(错​​误和成功)

javascript - 插入数组控制台日志可以看到但不会在 html 中呈现,为什么? Angular JS

ios - iOS Phonegap App中阿拉伯语显示不正确

node.js - 在企业代理 Node.js 后面访问 Github

javascript - 如何在 Angularjs 指令中渲染 html?

java - Cordova错误: Failed to execute shell command "getprop,dev.bootcomplete""

iphone - 付款被拒绝。请在您的计算机上为此金额添加有效的付款方式。 (iOS 中的 PayPal 实时模式)

ios - 如何使“更多”按钮始终进入“更多 View ”?

iOS - 打电话时在后台播放声音

android - iOS UI 元素移植到 Android