0

An Application that is designed for a device of 480x960 pixel resolution is executed on a 480x1136 device. While running on the 480x1136 device I need to be able to detect the real resolution. Unfortunately, instead of getting the device resolution ('480x1136'), I get the application resolution ( == '480x960'), hence [[UIScreen mainScreen] bounds].size * [[UIScreen mainScreen] scale] returns '480x960' instead of the expected '480x1136'

How can I resolve the real device physical resolution ?

Nick Kennedy
  • 12,510
  • 2
  • 30
  • 52
NadavRub
  • 2,520
  • 27
  • 63
  • What device are you testing this on? Physical device or simulator? – nhgrif Jun 28 '15 at 17:42
  • That's normal, because as far as the app is concerned, it is running on a device with a 480x960 resolution. Why do you need to get the actual resolution of the device? – Cihan Tek Jun 28 '15 at 17:45
  • A Physical device: an app designed to run on 3.5-inch device is executed on a 4 inch device ( iPod Touch 5,1 ) – NadavRub Jun 28 '15 at 17:45
  • So I could simulate remotely generated key-strokes in the correct position on the app – NadavRub Jun 28 '15 at 17:46

2 Answers2

0
//Get device screen resolution for this specific case     

CGRect boundsOfScreen=[[UIScreen mainScreen] bounds];

        if (boundsOfScreen.size.width == 480 && boundsOfScreen.size.height == 960 ) {
            //iPod Touch 3.5-inch
        }
        else if (boundsOfScreen.size.width == 480 && boundsOfScreen.size.height == 1136) {
             //iPod Touch 4-inch
        }
lukeswitz
  • 553
  • 4
  • 14
  • Using the above, How would you distinguish between eg. iPod Touch 3.5-inch ( 480x960 ) and iPod Touch 4-inch ( 480x1136 ) ? – NadavRub Jun 28 '15 at 18:20
  • U R resolving the device type using it's width, for the 3.5 & 4 inch devices the width is the same while the height is different, IMO a better way of resolving the device type is using what described in this link: http://stackoverflow.com/questions/11197509/ios-how-to-get-device-make-and-model , however, I would like to resove the resolution directly w/o maintaining a hard-coded table mapping type to resolution – NadavRub Jun 28 '15 at 18:24
  • regardless, what the above will return is the Application resolution and not the physical device resolution – NadavRub Jun 28 '15 at 18:25
  • I've tested it on three devices and simulator, it returns correct values. Apologies if it does not work for you. Edited original answer for your case but i believe it would work the same. – lukeswitz Jun 28 '15 at 18:29
0

It's Ugly, BUT, that's the only solution I have found to resolve the real physical main display resolution ( Independent of the executing app ):

#import <sys/utsname.h>

bool getDeviceNativeResolution(CGSize& res) {
    utsname si;
    uname(&si);

    if((0 == strncmp(si.machine, "iPod7", 5)) || (0 == strncmp(si.machine, "iPhone7", 7)))
        res = CGSizeMake(1080, 1920);
    else if((0 == strncmp(si.machine, "iPod6", 5)) || (0 == strncmp(si.machine, "iPhone6", 7)))
        res = CGSizeMake(750, 1334);
    else if((0 == strncmp(si.machine, "iPod5", 5)) || (0 == strncmp(si.machine, "iPhone5", 7)))
        res = CGSizeMake(640, 1136);
    else if((0 == strncmp(si.machine, "iPod4", 5)) || (0 == strncmp(si.machine, "iPhone4", 7)))
        res = CGSizeMake(640, 960);
    else
        return false;

    return true;
}
NadavRub
  • 2,520
  • 27
  • 63