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

如何检测iOS模拟器正在模拟的具体设备型号?

获取iOS模拟器的具体设备型号

原生代码实现(Swift)

通过读取模拟器独有的环境变量SIMULATOR_MODEL_IDENTIFIER拿到硬件型号标识,再映射为用户友好的设备名称:

import UIKit

func getSimulatorDeviceName() -> String? {
    guard let modelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] else {
        return nil
    }
    
    // 可根据苹果新机型更新映射表
    let modelMap: [String: String] = [
        "iPhone16,2": "iPhone 15 Pro Max",
        "iPhone16,1": "iPhone 15 Pro",
        "iPhone15,3": "iPhone 15 Plus",
        "iPhone15,2": "iPhone 15",
        "iPhone14,8": "iPhone SE (3rd generation)",
        "iPhone14,3": "iPhone 13 Pro Max",
        "iPhone14,2": "iPhone 13 Pro"
    ]
    
    return modelMap[modelIdentifier] ?? modelIdentifier
}

// 调用示例
if let deviceName = getSimulatorDeviceName() {
    print("正在模拟:\(deviceName)")
}

原生代码实现(Objective-C)

逻辑和Swift一致,通过环境变量获取型号标识后映射:

#import <Foundation/Foundation.h>

NSString *getSimulatorDeviceName() {
    NSString *modelIdentifier = [[NSProcessInfo processInfo] environment][@"SIMULATOR_MODEL_IDENTIFIER"];
    if (!modelIdentifier) {
        return nil;
    }
    
    NSDictionary *modelMap = @{
        @"iPhone16,2": @"iPhone 15 Pro Max",
        @"iPhone16,1": @"iPhone 15 Pro",
        @"iPhone15,3": @"iPhone 15 Plus",
        @"iPhone15,2": @"iPhone 15",
        @"iPhone14,8": @"iPhone SE (3rd generation)"
    };
    
    return modelMap[modelIdentifier] ?: modelIdentifier;
}

// 调用示例
NSString *deviceName = getSimulatorDeviceName();
if (deviceName) {
    NSLog(@"正在模拟:%@", deviceName);
}

命令行方式(Mac端调试用)

如果需要在终端或脚本中获取模拟器信息,使用xcrun simctl工具:

  • 查看所有已启动的模拟器:
    xcrun simctl list devices | grep Booted

  • 获取指定模拟器的型号标识:
    xcrun simctl getenv <模拟器UDID> SIMULATOR_MODEL_IDENTIFIER

替换<模拟器UDID>为已启动模拟器的UDID(可通过上面的命令获取)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 05:52:09