Checking which iPhone they are running

Discussion in 'iOS Programming' started by Kingbombs, Jun 19, 2010.

  1. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #1
    I know there is a way but having throuble with search results but i want to see if the user is running a 3GS or if they are running the versions before?

    bassicly something like
    if (version == 3GS)
    //do something
    else
    //code for earlier versions

    I know there are a few ways to do it, so please just put all the ones you know! Thanks!
     
  2. ahartford macrumors newbie

    Joined:
    Jun 1, 2010
    Location:
    Greater Boston
    #2
    Check the documentation for the UIDevice class. This should have everything you need. [UIDevice currentDevice].whateverProperty;
     
  3. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #3
    The class below is a category that will return the hardware model of the device, such as iPhone2,1 , iPod2,1 , Simulator return i386 ... I use this to tell the difference between different models of devices. There are also others ways such as check if the manometer is available if it is its and ipad or 3gs. Ect. but this is scalable to new devices.

    USAGE:
    Code:
    //Import into head or main.
    
    [UIDevice machine];//Returns a string
    
    
    Code:
    //
    //  UIDevice+machine.h
    //
    //  Created by Eric Rolf on 5/24/10.
    //
    
    #import <Foundation/Foundation.h>
    
    
    @interface UIDevice(machine)
    + (NSString *)machine;
    @end
    
    Code:
    //
    //  UIDevice+machine.m
    //
    //  Created by Eric Rolf on 5/24/10.
    //
    
    #import "UIDevice+machine.h"
    #include <sys/types.h>
    #include <sys/sysctl.h>
    
    @implementation UIDevice(machine)
    
    + (NSString *)machine
    {
    	size_t size;
    	
    	// Set 'oldp' parameter to NULL to get the size of the data
    	// returned so we can allocate appropriate amount of space
    	sysctlbyname("hw.machine", NULL, &size, NULL, 0); 
    	
    	// Allocate the space to store name
    	char *name = malloc(size);
    	
    	// Get the platform name
    	sysctlbyname("hw.machine", name, &size, NULL, 0);
    	
    	// Place name into a string
    	NSString *machine = [NSString stringWithCString:name encoding:NSASCIIStringEncoding];
    	
    	// Done with this
    	free(name);
    	
    	return machine;
    }
    
    @end
     

Share This Page