Sven Bauer
Sven Bauer

Reputation: 1689

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?

Upvotes: 2

Views: 5038

Answers (4)

Patrick Pijnappel
Patrick Pijnappel

Reputation: 7647

@jcesarmobile's answer in Swift:

ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]

Returns e.g. iPhone11,2 for iPhone Xs

Upvotes: 9

jcesarmobile
jcesarmobile

Reputation: 53301

You can get the device model with

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

Upvotes: 3

Pauls
Pauls

Reputation: 2636

You can't. The device model is based on the actual hardware running the iOS SDK, which in the simulator is the computer.

This pod provides easy access to all device models: https://github.com/InderKumarRathore/DeviceUtil

Upvotes: 1

user448228
user448228

Reputation: 88

Actually, iPhone simulator is one kind of model like the real device iPhone 3. You can refer the question here UIDevice currentDevice model possible values

Upvotes: 1

Related Questions