4

我正在C.I.下运行自动应用程序单元测试。环境的iPhone应用程序和一切工作正常使用命令行,如;从Xcodebuild启动用于持续集成的RETINA模拟器

xcodebuild -scheme "Tests" -configuration Debug -sdk iphonesimulator5.0 

这很好,但我现在想强制iPhone模拟器以Retina模式启动,而不是默认的标准模式。

我知道我可以切换硬件菜单选项,但我在无头集成服务器上运行这个,所以没有这个选项。

我想要做的事情是在命令行上通过一个开关,告诉模拟器在Retina模式下启动。

我乐观地尝试将SimulateDevice =“iPhone(Retina)”附加到xcodebuild命令,但似乎不起作用。

这可能吗?目前我似乎无法找到方法。

如果这是不可能的,是否有其他方法可以采取?

+0

是您的** ** xcodebuild联编命令实际上在启动模拟器中的应用程序?告诉我如何! – 2012-04-09 19:05:59

+0

请参阅https://gist.github.com/1365687和http://lifeandcode.net/2011/12/automated-ios-jenkins-builds-with-application-tests-and-core-data/和http:/ /longweekendmobile.com/2011/04/17/xcode4-running-application-tests-from-the-command-line-in-ios/对于我所关注的一些参考文献 – Roger 2012-04-10 12:54:26

回答

3

您应该使用AppleScript更改com.apple.iphonesimulator.plist中的SimulateDevice的值。

这是一个example这样做后提示用户选择所需的设备类型。您可以修改它以从命令行读取值或使用"iPhone (Retina)"作为默认值。

下面的脚本模拟器装置改变成通过命令行的值:

on run argv 

set selectedDevice to item 1 of argv as string 

set thePListFolderPath to path to preferences folder from user domain as string 
set thePListPath to thePListFolderPath & "com.apple.iphonesimulator.plist" 
tell application "System Events" 
    tell property list file thePListPath 
     tell contents 
      set value of property list item "SimulateDevice" to selectedDevice 
     end tell 
    end tell 
end tell 

end run 

而且可以从终端使用命令osascript执行它:

osascript myScript.scpt "iPhone (Retina)" 

或者

osascript myScript.scpt "iPhone" 

编辑

可以修改脚本,使它在默认情况下启动的Retina模拟器:

set selectedDevice to "iPhone (Retina)" 

set thePListFolderPath to path to preferences folder from user domain as string 
set thePListPath to thePListFolderPath & "com.apple.iphonesimulator.plist" 
tell application "System Events" 
    tell property list file thePListPath 
     tell contents 
      set value of property list item "SimulateDevice" to selectedDevice 
     end tell 
    end tell 
end tell 

最后请注意,更改"SimulateDevice"只需要在一个新的模拟器启动的效果。

+0

喜欢这种方法......在Lion上,尽管如此。它看起来像拱门-i386 osacript ...虽然会做到这一点。现在我得到脚本错误:期望的“结束”或“结束告诉”,但发现未知的标记。 (-2741) – Roger 2012-03-06 12:49:49

+0

修正了通过替换空格与制表符... – Roger 2012-03-06 13:12:12

+0

行,所以我实际上使用默认写入选项,因为这很容易,但你绝对让我在正确的轨道上,我需要applescript重新启动,所以我很乐意接受这个答案 - 非常感谢您花时间扩展您的答案。 – Roger 2012-03-06 13:51:35

5

另一种方法看起来像;

defaults write com.apple.iphonesimulator "SimulateDevice" '"iPhone (Retina)"' 

然而,由于来自SCH的AppleScript的做法,这似乎并没有作为构建阶段的一部分使用时是相当的工作。仍在调查......

+0

似乎没有工作作为运行脚本的一部分,我会尝试重新启动模拟器位虽然......但我怎么做到这一点从命令行? – Roger 2012-03-06 13:34:34

+0

用此处的另一个脚本解决了重新启动模拟器; HTTP://计算器。com/questions/5125243/how-can-i-reset-the-ios-simulator-from-the-command-line – Roger 2012-03-06 13:50:30

2

对于红宝石任何脚本,这里是设置仿真设备在模拟器的方法:参数的

def set_simulated_device(simulated_device) 
    current_simulated_device = `defaults read com.apple.iphonesimulator "SimulateDevice"`.chomp 

    if current_simulated_device != simulated_device 
     simulator_pid = `ps -ax|awk '/[i]Phone Simulator.app\\/Contents\\/MacOS\\/iPhone Simulator/{print $1}'`.chomp 
     Process.kill('INT', simulator_pid.to_i) unless simulator_pid.empty? 
     `defaults write com.apple.iphonesimulator "SimulateDevice" '"#{simulated_device}"'` 
    end 
    end 


列表可用于

“iPhone视网膜(3.5英寸) “
”iPhone视网膜(4英寸)“
”iPhone视网膜(4英寸64位)“
”ipad公司“
”ipad公司视网膜“
“iPad的视网膜(64位)”

0

您可以从iPhone模拟器二进制

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone模拟器做到这一点。应用程序/内容/的MacOS/iPhone \模拟器-SimulateDevice “iPhone视网膜(4英寸)”

其他版本:

  • “iPhone视网膜(3.5英寸)”
  • “iPhone视网膜(4英寸)“
  • “iPhone视网膜(4英寸64位)”
  • “ipad公司”
  • “ipad公司视网膜”
  • “ipad公司视网膜(64位)”
+0

这会正确打开模拟器......但是我们如何继续进行下去,因为我们无法控制直到我们关闭它 – 2013-12-05 13:34:30

+0

如果你启动仪器和模拟器已经运行它将使用模拟器的运行版本 – 2013-12-11 00:12:15

0

不告诉任何答案都错了..但这个工作了IOS 7

-- START:choose.sim.device 
on run argv 
    --set simType to item 1 of argv 
    tell application "iPhone Simulator" 
     activate 
    end tell 
    set simType to "Ipad Retina (64-bit)" 
    tell application "System Events" 
     tell process "iOS Simulator" 
      tell menu bar 1 
       -- Hardware menu bar item 
       tell menu bar item 5 
        -- Hardware menu 
        tell menu 1 
         -- Device menu item 
         tell menu item 1 
          -- Device sub menu 
          tell menu 1 
           click menu item simType 
          end tell 
         end tell 
        end tell 
       end tell 
      end tell 
     end tell 
    end tell 
    -- END:choose.sim.device 

    -- Need to show the simulator again after changing device, 
    -- or else the simulator be hidden when launched by instruments 
    -- for some odd reason. 
    tell application "System Events" 
     set visible of process "iPhone Simulator" to true 
    end tell 

    -- START:choose.sim.device 
end run 
-- END:choose.sim.device 

注意:它不是的 “iPad” 它的 “iPad”

+0

我也从某处得到了这个..我忘了在哪里 – 2013-12-06 06:25:21

0

Pro-tip创建一个别名。

alias ios="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateDevice” 

例子:

ios "iPhone Retina (3.5-inch)" 
ios "iPhone Retina (4-inch)" 
ios "iPhone Retina (4-inch 64-bit)" 
ios "iPad" 
ios "iPad Retina" 
ios "iPad Retina (64-bit)" 
+4

为什么要创建一个别名被认为是一个提示?请解释。 – rayryeng 2014-07-15 01:14:35

0

您可以指定与-destination标志的设备:

xcodebuild -scheme "Tests"  \ 
      -configuration Debug \ 
      -destination "platform=iOS Simulator,name=iPhone 6"