How to identify iPhone X

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
JackD
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 28
Joined: Sat Mar 14, 2009 3:17 am
Location: Olympia, WA USA

How to identify iPhone X

Post by JackD » Thu Mar 01, 2018 2:43 am

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.
27" iMac, OS X 10.13
iPad 3, iPad Pro, iPhone 4s, iPhone 6, LG Optimus L9 phone, Samsung Galaxy Camera
LiveCode 8.1.9

hlowe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8
Joined: Wed Dec 05, 2012 5:56 am

Re: How to identify iPhone X

Post by hlowe » Sun Mar 18, 2018 6:46 am

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

JackD
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 28
Joined: Sat Mar 14, 2009 3:17 am
Location: Olympia, WA USA

Re: How to identify iPhone X

Post by JackD » Sun Mar 18, 2018 7:00 am

Thanks, hlowe
27" iMac, OS X 10.13
iPad 3, iPad Pro, iPhone 4s, iPhone 6, LG Optimus L9 phone, Samsung Galaxy Camera
LiveCode 8.1.9

ronnysharma
Posts: 1
Joined: Sat Apr 28, 2018 2:37 pm

Re: How to identify iPhone X

Post by ronnysharma » Sat Apr 28, 2018 2:45 pm

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

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: How to identify iPhone X

Post by quailcreek » Fri Dec 28, 2018 2:22 am

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
Tom
MacBook Pro OS Mojave 10.14

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to identify iPhone X

Post by bogs » Fri Dec 28, 2018 2:22 pm

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)
Image

hlowe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8
Joined: Wed Dec 05, 2012 5:56 am

Re: How to identify iPhone X

Post by hlowe » Sat Dec 29, 2018 9:20 am

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

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: How to identify iPhone X

Post by quailcreek » Sun Dec 30, 2018 12:34 am

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
Tom
MacBook Pro OS Mojave 10.14

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to identify iPhone X

Post by jacque » Sun Dec 30, 2018 6:35 pm

Just curious, what does "the machine" return?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: How to identify iPhone X

Post by quailcreek » Sun Dec 30, 2018 11:14 pm

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()
Tom
MacBook Pro OS Mojave 10.14

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to identify iPhone X

Post by jacque » Mon Dec 31, 2018 1:42 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: How to identify iPhone X

Post by quailcreek » Mon Dec 31, 2018 3:34 am

I tested machine() on both of my iPhones and they both returned "iPhone"
Tom
MacBook Pro OS Mojave 10.14

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to identify iPhone X

Post by jacque » Mon Dec 31, 2018 5:54 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

hlowe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8
Joined: Wed Dec 05, 2012 5:56 am

Re: How to identify iPhone X

Post by hlowe » Sat Jan 05, 2019 12:26 am

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.

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: How to identify iPhone X

Post by quailcreek » Sat Jan 05, 2019 1:00 am

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.
Tom
MacBook Pro OS Mojave 10.14

Post Reply

Return to “iOS Deployment”