Identify Device and Firmware Version

Discussion in 'iOS Development' started by Axis, Jul 27, 2009.

  1. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Here's a basic tutorial on how to get the type of device (iPhone / iPod) and firmware version of someone using your application.

    The uses for this range from enabling certain features for a specific platform, or simply as an added nicety in UILabels, UIAlertViews, etc.

    *Look at the UIDevice class reference to see everything you can utilize with it*

    As an example, just say we want to display a UIAlertView explaining what device and firmware the user has.

    First,

    [OBJC]#import <UIKit/UIDevice.h>[/OBJC]

    So, we'll create two NSStrings, one for the model; the other for the firmware.

    [OBJC]NSString *deviceModel;
    NSString *firmwareVersion;[/OBJC]


    Now let's create that UIAlertView

    [OBJC]
    - (void)showAlert {
    deviceModel = [[UIDevice currentDevice] model];
    firmwareVersion = [[UIDevice currentDevice] systemVersion];
    NSString *alertString = [[NSString alloc] initWithFormat

    Please Register or Log in to view images

    "You're using an %@ with firmware %@", deviceModel, firmwareVersion];
    UIAlertView *test = [[UIAlertView alloc] initWithTitle

    Please Register or Log in to view images

    "Your device" message:alertString delegate:self cancelButtonTitle

    Please Register or Log in to view images

    "OK" otherButtonTitles:nil];
    [test show];
    [test release];
    [alertString release];
    [firmwareVersion release]; // must be released because we set its property to "retain"
    [deviceModel release]; // same as above
    }
    [/OBJC]

    Sample output:

    __


    Any constructive criticism is appreciated.
  2. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
  3. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    How is the showAlert method called? For people with no understanding of OBJ-C they would not know how to call that method
  4. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    This tutorial, albeit simple, is not meant for people with no Objective-C knowledge. If you or anyone doesn't have a basic understanding, this tutorial is not a place to start and is not advertised as such.

    To answer your question, this is not a practical example and I did not bother to make an app just for this function. This is the sort of thing that is implemented into a larger application.

    The showAlert method, in practice could be called in applicationDidFinishLaunching, or be called by the press of a button, when a timer fires - the possibilities continue.

    If you need me explain how things like that can be done, I'd be more than happy to. Just note, it was not the purpose of the tutorial.

Share This Page