How do I check what kind of device the user is running my Adobe AIR app on?
Example: if(device == ipad3) { stagestuff.width = 300; }
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityhttp://forums.adobe.com/thread/745385
At this link, it shows the following:
'Hi all,
I am sharing some of my library of iOS specific stuff in the hope that the community can suggest improvements and that it may be useful to others.
The following code can determine iPhone, iPodTouch and iPad based on screen res and geolocation (iTouch has no GPS). If anybody can help with code that can narrow the selection (i.e. determine between 3G, 3GS, 2nd gen, 3rd gen etc) that would be most welcome!
edit: hmm. Just realised that the iPhone 1st gen also didn't have GPS, so i can't use that to distinguish iTouch from iPhone...
package com.pixelthis.frameworks.ios
{
/**
* ...
* @author Peter Vullings
*/
public class DeviceType
{
import flash.system.Capabilities;
import flash.sensors.Geolocation;
// ------------------------------------------------------
// CONSTANTS
// ------------------------------------------------------
public static const IPHONE : int = 1;
//public static const IPHONE_3G : int = 2;
//public static const IPHONE_3GS : int = 3;
public static const IPHONE_4 : int = 4;
public static const IPODTOUCH : int = 100;
//public static const IPODTOUCH_2GEN : int = 101;
//public static const IPODTOUCH_3GEN : int = 102;
public static const IPAD : int = 200;
// ------------------------------------------------------
// PROPERTIES
// ------------------------------------------------------
public static var _currentDevice : int = 0;
// ------------------------------------------------------
// METHODS
// ------------------------------------------------------
/**
* Determine the current device type
* @return The device type
*/
public static function get currentDevice():int {
// If we have already calculated it, return it. The device
// isn't exactly going to change at run-time is it!
if (_currentDevice>0) return _currentDevice;
// Screen size
var w : int = Math.max( Capabilities.screenResolutionX, Capabilities.screenResolutionY );
var h : int = Math.min( Capabilities.screenResolutionX, Capabilities.screenResolutionY );
if (w <= 480){
if (Geolocation.isSupported){
_currentDevice = IPHONE;
}else{
_currentDevice = IPODTOUCH;
}
}else if (w<=960){
_currentDevice = IPHONE_4;
}else{
_currentDevice = IPAD;
}
return _currentDevice;
}
}
}'