[英]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.