Page 1 of 1

How to identify iPhone X

Posted: Thu Mar 01, 2018 2:43 am
by JackD
I've been looking at modifying an app to be iPhone X friendly by avoiding the safe areas at the top & bottom of a portrait screen. An app can run in compatibility mode but only if it is approved within the next month. Is there another way to identify an iPhone as model X other than checking the screen resolution (screenRect) which seems rather arbitrary? mergDeviceName() returns whatever a person has named their device and "the machine" simply returns iPhone.

Re: How to identify iPhone X

Posted: Sun Mar 18, 2018 6:46 am
by hlowe
Try this:

Function isIPhoneX
local tIsiPhoneX,tScreenRect,tScreenHeight,tScreenWidth
put false into tIsiPhoneX
put the ScreenRect into tScreenRect
if word 1 of the machine is "iPhone" and MobilePixelDensity() = 3 then
put item 3 of tScreenRect into tScreenWidth
put item 4 of tScreenRect into tScreenHeight
if (tScreenWidth = 375 and tScreenheight = 812) or (tScreenWidth = 812 and tScreenheight = 375) then
put true into tIsiPhoneX
end if
end if
return tIsiPhoneX
end isIPhoneX

Re: How to identify iPhone X

Posted: Sun Mar 18, 2018 7:00 am
by JackD
Thanks, hlowe

Re: How to identify iPhone X

Posted: Sat Apr 28, 2018 2:45 pm
by ronnysharma
hlowe wrote:
Sun Mar 18, 2018 6:46 am
Try this:

Function isIPhoneX
local tIsiPhoneX,tScreenRect,tScreenHeight,tScreenWidth
put false into tIsiPhone
X
put the ScreenRect into tScreenRect
if word 1 of the machine is "iPhone" and MobilePixelDensity() = 3 then
put item 3 of tScreenRect into tScreenWidth
put item 4 of tScreenRect into tScreenHeight
if (tScreenWidth = 375 and tScreenheight = 812) or (tScreenWidth = 812 and tScreenheight = 375) then
put true into tIsiPhoneX
end if
end if
return tIsiPhoneX
end isIPhoneX
Works just fine, thank you so much Hlowe! : D

Re: How to identify iPhone X

Posted: Fri Dec 28, 2018 2:22 am
by quailcreek
I've been looking on the web and with all the hoopla about apple and the screen size issues, I'm not able to find the size of the XS and the XS Max. I think the XS is the same size as the X. I'd like to be able to determine if my app is running on a X of any size. Can someone please shed some light on this?

If I run this code on my app on my SX MAX I get (320 568 2) which can't be right.

Code: Select all

 put the ScreenRect into tScreenRect
  put item 3 of tScreenRect into tScreenWidth
  put item 4 of tScreenRect into tScreenHeight
  put MobilePixelDensity() into tDensity
  answer "tScreenWidth" && tScreenWidth &CR& "tScreenHeight" && tScreenHeight &CR& "tDencity" && tDensity

Re: How to identify iPhone X

Posted: Fri Dec 28, 2018 2:22 pm
by bogs
I may be reading it wrong, but it looks to me like it is reporting 320x568x2 which I am reading as 640x1136.

Keep in mind I don't work with mobile, are phone resolutions bigger than that now?

*Edit - never mind, I guess they are!
https://www.apple.com/iphone-xs/specs/ wrote: Super Retina HD display
6.5‑inch (diagonal) all‑screen OLED Multi‑Touch display
HDR display
2688‑by-1242‑pixel resolution at 458 ppi
1,000,000:1 contrast ratio (typical)

Re: How to identify iPhone X

Posted: Sat Dec 29, 2018 9:20 am
by hlowe
This is the code that I now use to detect an iPhone X, Xs, Xr or Xs Max (the iPhones with notches). This replaces the IsIPhoneX function that I posted earlier this year.

function iPhoneHasNotch
local tiPhoneHasNotch,tScreenRect,tScreenHeight,tScreenWidth
put false into tiPhonehasNotch
if GetIOSDevice() is "iPhone" then
put the ScreenRect into tScreenRect
put item 3 of tScreenRect into tScreenWidth
put item 4 of tScreenRect into tScreenHeight
switch
case (tScreenWidth = 375 and tScreenheight = 812) or (tScreenWidth = 812 and tScreenheight = 375)
put true into tiPhoneHasNotch -- iPhone X or iPhone Xs
break
case (tScreenWidth = 414 and tScreenheight = 896) or (tScreenWidth = 896 and tScreenheight = 414)
put true into tiPhoneHasNotch -- iPhone Xr or iPhone Xs Max
break
end switch
end if
return tiPhoneHasNotch
end iPhoneHasNotch

function GetIOSDevice
return word 1 of the machine
end GetIOSDevice

Re: How to identify iPhone X

Posted: Sun Dec 30, 2018 12:34 am
by quailcreek
Thanks, hlowe

I adjusted your code a bit. No need for the extra function if you use platform()
The only problem is this will only return an iPhone X or iPhone Xs result because there isn't a Xr or Max splash screen choice in the standalone settings. I have reported this.

https://quality.livecode.com/show_bug.cgi?id=21767

Code: Select all

function iPhoneHasNotch
  local tiPhoneHasNotch,tScreenRect,tScreenHeight,tScreenWidth
  put false into tiPhonehasNotch
  
  if platform() is "iPhone" then
    put the ScreenRect into tScreenRect
    put item 3 of tScreenRect into tScreenWidth
    put item 4 of tScreenRect into tScreenHeight
    
    if (tScreenWidth = 375 and tScreenheight = 812) or (tScreenWidth = 812 and tScreenheight = 375) then
      --      put true into tiPhoneHasNotch -- iPhone X or iPhone Xs
      put "iPhone X or iPhone Xs" into tiPhoneHasNotch
      
    else if (tScreenWidth = 414 and tScreenheight = 896) or (tScreenWidth = 896 and tScreenheight = 414) then
      --      put true into tiPhoneHasNotch -- iPhone Xr or iPhone Xs Max
      put "iPhone Xr or iPhone Xs Max" into tiPhoneHasNotch
    end if
  end if
  return tiPhoneHasNotch
end iPhoneHasNotch

Re: How to identify iPhone X

Posted: Sun Dec 30, 2018 6:35 pm
by jacque
Just curious, what does "the machine" return?

Re: How to identify iPhone X

Posted: Sun Dec 30, 2018 11:14 pm
by quailcreek
Hi J,
I just checked each of these on the sim, my iPhone 6s, iPhone XS Max and my Samsung Galaxy J7 and they return what the docs say. In the sim, machine() returns iPhone Simulator. That's why I chose platform(). On my Samsung machine() returns some kind of serial number. Platform() returns iPhone and android respectively.

Code: Select all

answer "Machine" && machine() &CR& "Platform" && platform() &CR& "Environment" && environment()

Re: How to identify iPhone X

Posted: Mon Dec 31, 2018 1:42 am
by jacque
The platform will return "iPhone" even if it's an iPad, if that matters. On a real device "the machine" should return the model. On my Android devices, the machine returns "Pixel", "Nexus 7", or "SHT-W09" (my Huawei tablet.) I'd expect iOS devices to return their names too, but maybe someone with an iPhone can tell us. My husband has his tightly clenched in his hand, so I can't steal it to find out.

Re: How to identify iPhone X

Posted: Mon Dec 31, 2018 3:34 am
by quailcreek
I tested machine() on both of my iPhones and they both returned "iPhone"

Re: How to identify iPhone X

Posted: Mon Dec 31, 2018 5:54 am
by jacque
quailcreek wrote:
Mon Dec 31, 2018 3:34 am
I tested machine() on both of my iPhones and they both returned "iPhone"
Ah. That's too bad. I guess you're stuck measuring the screenrect then. It's different on Android where more information about the device is readily available.

Re: How to identify iPhone X

Posted: Sat Jan 05, 2019 12:26 am
by hlowe
I have tested iPhoneHasNotch() on an iPhone X, iPhone Xs, iPhone Xr and iPhone Xs Max and it returns true (as expected) in each case. The function returns false on an iPhone 6S (which has no notch), also as expected.

Re: How to identify iPhone X

Posted: Sat Jan 05, 2019 1:00 am
by quailcreek
I have tested it too, hlowe. In order for iPhoneHasNotch() to return the size of the XS Max/Xr screens you need to be able to incorporate the Max/Xr splash screens. These won't be available until LC9.0.3 rc1. Right now you're only seeing the iPhoneX screen size.

Try putting something else besides true into tiPhoneHasNotch like in the modified code I posted.