Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

iPhoneX detection on device and in simulator
Started by troylyndon Jul 30 2018 01:51 PM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 485 posts
  • Corona SDK

1) Without our ability to detect the iPhone X skin in the simulator, all of my custom code to nicely place UI elements around the top inset cannot be seen unless I see it on an actual device. So, is there a way to detect iPhone X skin from within our code?

 

2) is this code the definitive test if an actual device is an iPhone X? Or how should it be adjusted?

 

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

      if f==true then
        -- true means this code runs if on an actual iPhone X+ device, including future phones with insets?
      end
 

 



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,923 posts
  • Corona SDK

If you're using SSK (https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/system/#actual-device-flags), just do this:
if( oniPhoneX ) then
  -- your special iPhoneX code
end
You can detect this yourself using this code:
local actualWidth = math.floor((display.actualContentWidth/display.contentScaleX)+0.5)
local actualHeight = math.floor((display.actualContentHeight/display.contentScaleY)+0.5)
 
local function matchesWH(width,height)
   return( (width == actualWidth and height == actualHeight) or 
           (height == actualWidth and width == actualHeight) ) 
end 

local oniPhoneX = ( string.find( architectureInfo, "iPhone10,3" ) ~= nil ) or 
                  ( string.find( architectureInfo, "iPhone10,6" ) ~= nil ) or 
                  (system.getInfo("environment") == "simulator" and matchesWH(1125,2436) )


Edited by roaminggamer, 30 July 2018 - 05:08 PM.


[TOPIC: post.html]
#3

troylyndon

[GLOBAL: userInfoPane.html]
troylyndon
  • Contributor

  • 485 posts
  • Corona SDK

(SOLVED) based upon your response, I can conclude that to test if a device is on iPhoneX, I would use the following...

if (system.getInfo("platform")=="ios" and (string.find( system.getInfo("architectureInfo"),"iPhone10,3")~= nil) or (string.find(system.getInfo("architectureInfo"),"iPhone10,6" )~= nil)) or (system.getInfo("environment")=="simulator" and display.viewableContentHeight==2436 and display.viewableContentWidth==1125) then

  -- CODE would go here if 1) actual device is iOS and iPhoneX and 2) if in simulator mode running iPhoneX skin
end




[topic_controls]
[/topic_controls]