Forum Archive

How to detect retina display

mikashkin

Hello,

Working on the project I found that I need to detect what type of the screen have device that running my code. And made this simple detector. Probaby it is not something big, but for me this is first bites of code that uses objc bindings. Hope you will find it useful

Grab the gist isretina.py or code

from objc_util import *
us = ObjCClass('UIScreen')
if us.mainScreen().scale() == 2.0:
    print('Retina')
elif us.mainScreen().scale() == 3.0:
    print('iPhone Plus')
else:
    print('Non retina')
omz

You could also use scene.get_screen_scale() for this (which is basically just a wrapper around [[UIScreen mainScreen] scale) – nothing wrong with your code, just wanted to point out that it's not necessary to delve into ObjC for this.

ccc
from objc_util import ObjCClass
scale = ObjCClass('UIScreen').mainScreen().scale()
print({2: 'Retina', 3: 'iPhone Plus'}.get(scale, 'Non retina'))