February 28, 2009

Detecting Device information on the iPhone

Posted in iPhone development tagged , , , , , , , , , , , , at 9:49 pm by tetontech

Detecting the device specific information for the device your application is running on is very easy. The code below shows how this is done in QuickConnectiPhone 1.5 Beta 2 that will soon be released.  It is found in the GetDeviceInfoVCO.m file.

I am gathering the following and putting it in an array so that the data can be passed up to the JavaScript.

  1. The device unique identifier
  2. The name of the device
  3. The localized version of the model of the device (iPhone, iPod Touch)
  4. The system name (iPhone OS)
  5. The system version (2.2.1, etc.)
  6. The language and locale used on the device(en_US)
  7. The short version of the time zone (MST)

UIDevice *aDevice = [UIDevice currentDevice];

NSLocale *currentLocale = [NSLocale currentLocale];

NSTimeZone *timeZone = [NSTimeZone systemTimeZone];

NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];

NSMutableArray *passingArray = [[NSMutableArray alloc] initWithCapacity:5];

[passingArray addObject: [aDevice uniqueIdentifier]];

[passingArray addObject: [aDevice name]];

[passingArray addObject: [aDevice localizedModel]];

[passingArray addObject: [aDevice systemName]];

[passingArray addObject: [aDevice systemVersion]];

[passingArray addObject: [defs objectForKey:@”AppleLocale”]];

NSString *timeZoneString = [timeZone localizedName:NSTimeZoneNameStyleShortStandard locale:currentLocale];

if([timeZone isDaylightSavingTimeForDate:[NSDate date]]){

timeZoneString = [timeZone localizedName:NSTimeZoneNameStyleShortDaylightSaving locale:currentLocale];

}

[passingArray addObject: timeZoneString];

The JavaScript to display this information, found in the functions.js file of the DeviceDescriptionExample, is seen here.

function displayDeviceInfoVCF(data, paramArray){

document.getElementById(‘devDisplay’).innerText = ‘UDID: ‘+paramArray[0]+‘\n\ndevice name: ‘+paramArray[1]+‘\n\nmodel: ‘+paramArray[2]

+‘\n\nsystem: ‘+paramArray[3]+‘\n\nOS version: ‘+paramArray[4]+‘\n\nLanguage and Locale: ‘+paramArray[5]+‘\n\nTimeZone: ‘+paramArray[6];

}

Here is an image of this code running in the DeviceDescriptionExample application incuded in QC 1.5

A display of the information about the device running the application

A display of the information about the device running the application

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: