简体   繁体   中英

How to detect the iPad pro running in the simulator?

I've found a lot of posts on device detection and screen size. But none of these work with the simulator.

The simulator device type normally returns x86_64.

And the screen size [UIScreen mainScreen].bounds.size.height returns 1024.

I have a scenario when I need to make an adjustment to drawing code which sizing classes don't cater for.

I'm stumped.

Even though i think you're not supposed to manually do this, here are some options.

Firstly you could multiply the bounds by the scale:

CGSize size = [UIScreen mainScreen].bounds.size;
CGFloat scale = [UIScreen mainScreen].scale;
CGSize realSize = CGSizeMake(size.width * scale, size.height * scale);

Or since iOS 8 you can actually do it easier:

CGSize realSize2 = [UIScreen mainScreen].nativeBounds.size;

and according to the documentation the second way ignores orientation, so is probably easier to check.

Hopefully this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM