Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Determine what iOS device the project is running on

edited September 2013 in Questions Posts: 4

I read through the roadmap that there is a deviceMetrics() function available, but I could not find any documentation on it. When using the following code:

    info = deviceMetrics()
    for i, line in ipairs(info) do
       print (line) 
    end

Nothing is printed. I'm new to Lua (programmed for 18 years with other languages) so I'm struggling a little trying to determine if the table is just blank or if I am reading it wrong.

Since the documentation does not really tell me what data the deviceMetrics() stores in the returned table, I am kind of at a loss when it comes to determining what device the project is running on.

Any help would be greatly appreciated! I know I could probably use the WIDTH and HEIGHT constants to determine it based on screen resolution, but I assumed that deviceMetrics would provide a simpler approach.

Tagged:

Comments

  • dave1707dave1707 Mod
    edited September 2013 Posts: 9,586

    @Scionwest Try pairs instead of ipairs.

  • edited September 2013 Posts: 4

    @dave1707 Awesome thanks, that fixed it. I also found additional documentation on the wiki (which I wasn't aware existed until 2 minutes ago lol). So I was able to adjust my code to just check the platform like such:

        myDevice = deviceMetrics().platform
    
  • Something else I noticed while doing this is that the deviceMetrics() function does not differentiate an iPad mini from a full size iPad. So my iPad mini is returned as iPad 2G. I suppose this isn't an issue since they are the same screen resolution, just thought it was interesting.

  • Note: iPad 4's name appears as iPad3,4 instead of iPad4 in one of the deviceMetrics() variables, can't remember which, though. Maybe platform?

Sign In or Register to comment.