问题
I've looked at all the code available for determining the device that an app is running on, but how can you tell what device is running in the simulator?
I've never had this issue before because I've always had hardware to test with. Now that the iPhone 6/6+ is out, I only have the 6+, but need to test on the 6 in the simulator. When I use this thread to determine what device I'm running on, all I get is the simulator.
Thanks.
回答1:
Although other comments have a point, you do not really need to know what device you are running on, what you do need to know is, what functionalities do you have available. And even so, if you just want to output this message, it would be wrong to display iPhone 6 instead of Simulator. Just add the correct code for the iPhone 6 model and it should work, not really much that can go wrong here.
But if you still want to support this, I would go with checking hardcoded resolutions for each device. Since programatically there is no difference between 6+ and 6, except for resolution you could use this. But know that Simulator can be virtually any size you pick, so you must have a fallback logic for this.
So the resolutions are (in logic points):
- 320 x 480 - iPhone 4/4S
- 320 x 568 - iPhone 5/5C/5S
- 375 x 667 - iPhone 6
- 414 x 736 - iPhone 6+
From this you can already see that resolution is really not the best way, as you cannot see the difference between iPhone 5 phones as well as iPhone 4. You can add additional checks to get around this, you can separate iPhone 5S by checking if Touch ID is available or similar. But you will not be able to get around the problem completely.
来源:https://stackoverflow.com/questions/26044221/how-to-determine-the-device-running-in-the-simulator