Buggy Device::getDPI()

I need device DPI information. I use cocos2d::Device::getDPI() function but it returns incorrect values.
On iPad mini the expected value is 324 but the returned value is 264.
Am I misinterpreting something or is there a bug?

Same here. Did you ever find a fix?

@corytrese is this still an issue? Any numbers you can provide as to what sizes are being returned in what devices?

For iPads, I always get 132 or 264. I’ve tested on a bunch today (Air2, Mini3, Gen4, Gen5) and the code doesn’t seem to treat them differently.

int Device::getDPI()
{
		static int dpi = -1;

		if (dpi == -1)
		{
				float scale = 1.0f;

				if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
						scale = [[UIScreen mainScreen] scale];
				}

				if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
						dpi = 132 * scale;
				} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
						dpi = 163 * scale;
				} else {
						dpi = 160 * scale;
				}
		}
		return dpi;
}

This code doesn’t seem particularly smart or accurate when it comes to the different devices. I’d expect to get 324 for some devices. This code cannot even return 324 for the mini retina, it might return 396 if scale was 3, but I don’t think that ever happens.

Halp! <3

@drelaptop @zhangxm what do you think about this?

There is no any public api in ios to know physical screen size of device. Look at https://github.com/lmirosevic/GBDeviceInfo project, it return dpi for any apple device, but it held this info on per model per table basis and update tables regularly.

We just know because Apple tells us in products descriptions. There is this: http://iosres.com