首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将默认设备设置为在Ionic中进行模仿?

如何将默认设备设置为在Ionic中进行模仿?
EN

Stack Overflow用户
提问于 2016-02-09 15:45:12
回答 1查看 1.8K关注 0票数 4

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

代码语言:javascript
复制
ionic emulate ios --target="iPad-2"

有没有一种方法可以在ionic.project文件中或其他地方对此进行硬编码,这样我就可以停止手工操作了吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-10 07:17:58

我经历了同样的问题,尽管这个问题已经存在了一年,但这是我第一次在谷歌上找到答案,在其他地方也找不到答案。我之所以这么做是因为我不想每次都使用--target="iPhone-7“。

要让任何想要在特定ios设备上运行的人明白这一点,请使用以下方法:

代码语言:javascript
复制
ionic run ios --target="iXXX-X"

例如,iXXX-X将是运行ios-sim showdevicetypes时获得的名称之一:

代码语言:javascript
复制
ionic run ios --target="iPhone-7"

我希望有一个解决方案,使iPhone-7成为我的默认设置,因此运行以下程序将针对iPhone-7 (我最初的默认目标是iPhone):

代码语言:javascript
复制
ionic run ios

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

在这里您可以找到一个名为deployToSim的函数,我对它做了如下修改:

代码语言:javascript
复制
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);
  }
}

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35296187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档