Is there a way to detect if the app is running on an iPhone X?

I’d like to be able to determine whether or not to re position centered text or buttons at the top of the screen under the ‘notch’.

Thanks.

  1. This has been discussed here a quite a lot.  Try googling ==>  site: coronalabs.com iphonex

https://www.google.com/search?q=site%3A+coronalabs.com+iphonex&oq=site%3A+coronalabs.com+iphonex&aqs=chrome…69i57j69i58.18687j0j7&sourceid=chrome&ie=UTF-8

  1. Yes, you can determine what iphone you are on easily.  SSK2 does this for you:

    if( ssk.system.oniPhoneX ) then … end

You can also steal my code to detect this:

https://github.com/roaminggamer/SSK2/blob/master/ssk2/system.lua

local oniPhoneX = ( string.find( system.getInfo("architectureInfo"), "iPhone10,3" ) ~= nil ) or ( string.find( system.getInfo("architectureInfo"), "iPhone10,6" ) ~= nil )

Thanks roaminggamer once again!

Hi 

on Xcode iPhone x simulator this return false, since system.getInfo(“architectureInfo”) is x86_64. can I tell if I’m on iphoneX simulator. just to modify app layout

You mean you’re running the corona simulator or a PC or Mac with the iPhoneX skin.

Yes, that is right.  It is supposed to be detecting the actual system you’re on, not the skin.

There may be a way to detect the selected skin, but if there is I don’t remember how.   This may seem like a convenience, but for me it would be a huge pain. 

When I code I always want to know the real OS and system I’m on.  But then this is because I write tools and advanced code that depends on this for developing. 

I think you will have to do what I do.  Use a flag.

i.e. After you do your detection code,

\_G.oniPhoneX = ( string.find( system.getInfo("architectureInfo"), "iPhone10,3" ) ~= nil ) or ( string.find( system.getInfo("architectureInfo"), "iPhone10,6" ) ~= nil )

just do this:

\_G.oniPhoneX = true

Now test with the iPhone X skin.  Done.

You could set up your detection code like this too:

  1. In main.lua 

    _G.skin = “iPhoneX”

  2. Then in detection code:

    _G.oniPhoneX = _G.skin == “iPhoneX” or ( string.find( system.getInfo(“architectureInfo”), “iPhone10,3” ) ~= nil ) or ( string.find( system.getInfo(“architectureInfo”), “iPhone10,6” ) ~= nil )

Now, just remember to comment out the code in main when you go to production and you’re golden.

This is nice because it can be used for other settings too.

If neither of these is suitable, dig though system.* and other libraries.  If you find a solution for detecting skin, post back.

I don’t think it exists however.

One simple way is just compare the display.pixelWidth and pixelHeight with the iPhoneX… Here is what I use:

 M.isSimulator = "simulator" == system.getInfo("environment") -- checking if we are in Corona Simulator M.is\_iPhoneX = false if string.find(architectureInfo, "iPhone10,3") or string.find(architectureInfo, "iPhone10,6") then M.is\_iPhoneX = true end if M.is\_iPhoneX == false and M.isSimulator and display.pixelWidth == 1125 and display.pixelHeight == 2436 then M.is\_iPhoneX = true end
  1. This has been discussed here a quite a lot.  Try googling ==>  site: coronalabs.com iphonex

https://www.google.com/search?q=site%3A+coronalabs.com+iphonex&oq=site%3A+coronalabs.com+iphonex&aqs=chrome…69i57j69i58.18687j0j7&sourceid=chrome&ie=UTF-8

  1. Yes, you can determine what iphone you are on easily.  SSK2 does this for you:

    if( ssk.system.oniPhoneX ) then … end

You can also steal my code to detect this:

https://github.com/roaminggamer/SSK2/blob/master/ssk2/system.lua

local oniPhoneX = ( string.find( system.getInfo("architectureInfo"), "iPhone10,3" ) ~= nil ) or ( string.find( system.getInfo("architectureInfo"), "iPhone10,6" ) ~= nil )

Thanks roaminggamer once again!

Hi 

on Xcode iPhone x simulator this return false, since system.getInfo(“architectureInfo”) is x86_64. can I tell if I’m on iphoneX simulator. just to modify app layout

You mean you’re running the corona simulator or a PC or Mac with the iPhoneX skin.

Yes, that is right.  It is supposed to be detecting the actual system you’re on, not the skin.

There may be a way to detect the selected skin, but if there is I don’t remember how.   This may seem like a convenience, but for me it would be a huge pain. 

When I code I always want to know the real OS and system I’m on.  But then this is because I write tools and advanced code that depends on this for developing. 

I think you will have to do what I do.  Use a flag.

i.e. After you do your detection code,

\_G.oniPhoneX = ( string.find( system.getInfo("architectureInfo"), "iPhone10,3" ) ~= nil ) or ( string.find( system.getInfo("architectureInfo"), "iPhone10,6" ) ~= nil )

just do this:

\_G.oniPhoneX = true

Now test with the iPhone X skin.  Done.

You could set up your detection code like this too:

  1. In main.lua 

    _G.skin = “iPhoneX”

  2. Then in detection code:

    _G.oniPhoneX = _G.skin == “iPhoneX” or ( string.find( system.getInfo(“architectureInfo”), “iPhone10,3” ) ~= nil ) or ( string.find( system.getInfo(“architectureInfo”), “iPhone10,6” ) ~= nil )

Now, just remember to comment out the code in main when you go to production and you’re golden.

This is nice because it can be used for other settings too.

If neither of these is suitable, dig though system.* and other libraries.  If you find a solution for detecting skin, post back.

I don’t think it exists however.

One simple way is just compare the display.pixelWidth and pixelHeight with the iPhoneX… Here is what I use:

 M.isSimulator = "simulator" == system.getInfo("environment") -- checking if we are in Corona Simulator M.is\_iPhoneX = false if string.find(architectureInfo, "iPhone10,3") or string.find(architectureInfo, "iPhone10,6") then M.is\_iPhoneX = true end if M.is\_iPhoneX == false and M.isSimulator and display.pixelWidth == 1125 and display.pixelHeight == 2436 then M.is\_iPhoneX = true end