You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过xcrun simctl命令行获取iOS设备屏幕分辨率?

获取iOS模拟器屏幕分辨率的几种可行方法

确实,xcrun simctl list -j devicetypes 只返回设备类型的基本标识和名称信息,完全不包含屏幕分辨率数据。不过有几个实用的办法能帮你拿到想要的信息,我一个个拆解给你:

方法1:通过system_profiler直接从运行的模拟器获取

这个方法需要先启动目标模拟器,然后通过simctl spawn命令调用系统工具获取显示信息:

  1. 先获取你要查询的模拟器UDID(或者直接用设备名称,比如"iPhone 15 Pro"):
    xcrun simctl list devices
    
  2. 启动该模拟器(如果还没启动的话):
    xcrun simctl boot <模拟器UDID或名称>
    
  3. 执行命令获取屏幕分辨率:
    xcrun simctl spawn <模拟器UDID或名称> system_profiler SPDisplaysDataType
    
    输出里会包含Resolution字段,比如1179 x 2556。如果想直接提取数值,可以用grep和awk过滤:
    xcrun simctl spawn <模拟器UDID或名称> system_profiler SPDisplaysDataType | grep -A1 Resolution | tail -n1 | awk '{print $1}'
    

方法2:读取CoreSimulator的设备类型配置文件

Xcode在安装时会为每个设备类型存储配置plist文件,里面直接包含默认屏幕宽高。路径一般在Xcode的安装目录下:

  1. 定位到设备类型的plist目录(如果是App Store安装的Xcode,路径就是下面这个):
    cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/DeviceTypes/
    
  2. 查看所有设备类型的文件夹,比如iPhone 15 Pro.devicetype
  3. 用plutil命令读取分辨率数据:
    # 获取宽度
    plutil -extract defaultScreenWidth integer /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/DeviceTypes/iPhone\ 15\ Pro.devicetype/Contents/Info.plist
    # 获取高度
    plutil -extract defaultScreenHeight integer /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/DeviceTypes/iPhone\ 15\ Pro.devicetype/Contents/Info.plist
    
    这个方法不需要启动模拟器,直接读取配置文件,适合批量查询设备类型的分辨率。

方法3:通过截图获取分辨率(简单直观)

如果模拟器已经启动,你可以先截一张屏,然后用图片工具读取尺寸:

  1. 截取模拟器屏幕:
    xcrun simctl io <模拟器UDID或名称> screenshot /tmp/sim_screen.png
    
  2. 用sips命令获取图片的像素尺寸:
    sips -g pixelWidth -g pixelHeight /tmp/sim_screen.png
    
    输出会直接显示屏幕的宽高像素值,比如:
    pixelWidth: 1179
    pixelHeight: 2556
    

内容的提问来源于stack exchange,提问作者Zaphod

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 07:57:51