简体   繁体   English

在模拟器上运行时获取设备型号名称?

[英]Get the Device model name when running on Simulator?

I know that the device's model name can be retrieved with: 我知道可以通过以下方式检索设备的型号名称:

let device: UIDevice = UIDevice.currentDevice()
println("device.model: \(device.model)")

The problem is that this does not work when running in the simulation. 问题是,在模拟中运行时,这不起作用。 The result would be: 结果将是:

device.model: iPhone Simulator

It works on the device but I want to know which device the simulator is simulating. 它可以在设备上运行,但是我想知道模拟器正在仿真哪个设备。

How can I get the Device model name when running on Simulator? 在模拟器上运行时,如何获取设备型号名称?

您可以通过以下方式获取设备型号

NSString * model = [NSString stringWithFormat:@"%s" , getenv("SIMULATOR_MODEL_IDENTIFIER")];

You can't. 你不能 The device model is based on the actual hardware running the iOS SDK, which in the simulator is the computer. 设备模型基于运行iOS SDK的实际硬件,在模拟器中为计算机。

This pod provides easy access to all device models: https://github.com/InderKumarRathore/DeviceUtil 该pod可以轻松访问所有设备型号: https//github.com/InderKumarRathore/DeviceUtil

实际上,iPhone模拟器是类似于真实设备iPhone 3的一种模型。您可以在此处引用问题UIDevice currentDevice模型的可能值

@jcesarmobile 's answer in Swift: @jcesarmobile在Swift中的答案:

ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]

Returns eg iPhone11,2 for iPhone Xs 返回例如iPhone Xs的iPhone11,2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:无法获得默认输入设备......在模拟器上运行时 - Error: couldn't get default input device… when running on simulator 在iOS设备上运行但不在模拟器中运行时,SIGABRT错误 - SIGABRT Error when running on an iOS device but not in simulator 为什么在设备上而不在模拟器上运行时会破坏数据? - Why a data will be destroyed when running on device but not on simulator? 在Simulator中运行时的条件编译,而不是在设备上运行 - Conditional compile when running in Simulator as opposed to on a device HTMLKit 在模拟器上运行但不在设备上 - HTMLKit running on simulator but not on device Swift Admob控制台显示模拟器设备ID,但在iPhone上运行时却没有? - Swift Admob console displays simulator device ID but not when running on iPhone? 在iOS设备(而非模拟器)上运行时,从CGRectMake获取异常 - Getting an exception from CGRectMake when running on iOS device (but not simulator) os_signpost在模拟器上工作,但在设备上运行时不工作 - os_signpost works on simulator but not when running on device -lxml2找不到库,仅当在设备而不是模拟器上运行时 - library not found for -lxml2 Only when running on Device, not Simulator 如何确定模拟器中正在运行的设备? - How to determine the device running in the simulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM