Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kingbombs

macrumors member
Original poster
Jun 24, 2009
98
0
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!
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.