Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Detect iPhone 4 devices

I have improved all the graphics in my apps but I want to be able to detect wether the user has an iPhone 4 or not. The higher quality tab bar icons don't look so good on older devices. I'd like to just detect the higher res display.

I thought about using this:

Titanium.Platform.displayCaps.dpi

In the simulator, the iPhone 4 returns 160 so I know it's not working there. Any ideas of how to detect an iPhone 4?

— asked July 1st 2010 by Andrew Flocchini
  • iphone4
1 Comment
  • Titanium.Platform.model might be a solution but I don't know exactly what this returns on an iPhone4. Can anyone try it out?

    — commented July 1st 2010 by Andrew Flocchini

4 Answers

  • Accepted Answer

    Andrew,

    That doesn't work. I tried to do the same thing for one of my apps, but when you use Titanium.Platform.model it doesn't come back as iPhone 4 when on a iPhone 4, it just says iPhone for me.

    — answered July 1st 2010 by donovan lewis
    permalink
    1 Comment
    • I guess, until I can come up with a good way to identify iPhone 4's, the tab icons are going to suffer on older devices.

      — commented July 1st 2010 by Andrew Flocchini
  • by "in the simulator the iphone returns 160" you mean even after choosing the iphone4 in the simulator menue under hardware/devices?

    what about the screen-dimension: do you get the real pixels for width and height? if so using Titanium.Platform.osname combined with a screensize of 960px (i guess) would mean your app is running on the iphone4

    — answered July 1st 2010 by Christian Sigl
    permalink
    1 Comment
    • In the simulator, the iPhone4 and the regular iPhone devices both report a 160 dpi, a low display density, 320 width & 480 height. I don't have a real iPhone4 to test this out on so I have to rely on the simulator.

      — commented July 1st 2010 by Andrew Flocchini
  • You can find an example here http://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/version.js

    — answered July 1st 2010 by David Ashwood
    permalink
    4 Comments
    • Since different iPhone's and iPods can run 4.0, I don't think this will help. I need to detect an iPhone4 so I can tell it to use higher res images in the tab bar.

      — commented July 1st 2010 by Andrew Flocchini
    • That should be up to Ti to detect.
      With the right suffix to the image files (@2 iirc) - it'll use either the highres image or the low-res image. You just include both files as a resource.

      — commented July 1st 2010 by David Ashwood
    • You can see a specific example with this commit http://github.com/appcelerator/titanium_mobile/commit/2e3fc870812b8a9623c6840dc01572ad6c038e1b

      — commented July 1st 2010 by David Ashwood
    • On my iPod 2G with 4.0, it shows the 2x icons. They're downscaled and look bad. On devices that aren't iPhone4's I need to show my original icons. Here's the code.

      function isiOS4Plus()
      {
          // add iphone specific tests
          if (Titanium.Platform.name == 'iPhone OS')
          {
              var version = Titanium.Platform.version.split(".");
              var major = parseInt(version[0]);
      
              // can only test this support on a 3.2+ device
              if (major >= 4)
              {
                  return true;
              }
          }
          return false;
      };
          if (isiOS4Plus())
          {    
          var tab2 = Titanium.UI.createTab({  
              icon:'calc_icon@2x.png',
              title:'Fog',
              window:win2
          })
          } else {
          var tab2 = Titanium.UI.createTab({  
              icon:'calc_icon.png',
              title:'Fog',
              window:win2
          })
          };
      

      I'd like to try the command:

      Titanium.Platform.model
      

      But I don't have a physical iPhone4 to see what is returned.

      — commented July 1st 2010 by Andrew Flocchini
  • This what I found to work for me. I don't have an iPhone 4 to test it 100%.

        if (Titanium.Platform.model=='iPhone 4' || Titanium.Platform.model=='Simulator')
        {    
        var tab2 = Titanium.UI.createTab({  
            icon:'calc_icon@2x.png',
            title:'Fog',
            window:win2
        })
        } else {
        var tab2 = Titanium.UI.createTab({  
            icon:'calc_icon.png',
            title:'Fog',
            window:win2
        })
        };
    
    — answered July 1st 2010 by Andrew Flocchini
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.