Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

How to identify which device the user is on?

ghostghost Posts: 271Registered Users @ @
edited November 2010 in iPhone SDK Development
My app can take a photo, but I want to disable this for 1st gen iPod Touch owners. How do I know what device the app is running on?
Thanks
Post edited by ghost on

Replies

  • xnakxxnakx Posts: 130Registered Users
    edited October 2008
    [[UIDevice currentDevice] model];
    [[UIDevice currentDevice] systemVersion];
    [[UIDevice currentDevice] systemName];
    
    should get you the info you need.
  • ghostghost Posts: 271Registered Users @ @
    edited October 2008
    Do you know what the "model" call returns?
  • xnakxxnakx Posts: 130Registered Users
    edited October 2008
    i think mine says "iPhone" and the system version says "2.1"
  • tmbgtmbg Posts: 33Registered Users
    edited October 2008
    it's in the iPhone developers guide somewhere... you'll get "iPhone" or "iPod Touch"
  • ghostghost Posts: 271Registered Users @ @
    edited October 2008
    The API said I would get an NSString. It contains a value *like* "iPhone" or "iPod touch"
    I need to know which generation the iPod touch is, though
  • DeklannDeklann Posts: 32Registered Users
    edited October 2008
    ghost wrote: »
    The API said I would get an NSString. It contains a value *like* "iPhone" or "iPod touch"
    I need to know which generation the iPod touch is, though

    Why does that matter? Neither generation of iPod Touch can take a photo.
    <b><a href="http://www.sdkcoder.com" target="_blank">www.sdkcoder.com</a></b><br />
    <font size="1">Are my posts helping you? Please help support my forum!<br />
    <i>Aiming to be one of the most comprehensive iPhone resources on the net.</i></font>
  • ghostghost Posts: 271Registered Users @ @
    edited October 2008
    For some reason I had been thinking the new iPod Touch could! My bad!
    What's weird though is my app was first rejected because it had a camera function and I made it available to all devices. I resubmitted it as iPhone/iPodTouch2G and it was approved...
  • DeklannDeklann Posts: 32Registered Users
    edited October 2008
    ghost wrote: »
    For some reason I had been thinking the new iPod Touch could! My bad!
    What's weird though is my app was first rejected because it had a camera function and I made it available to all devices. I resubmitted it as iPhone/iPodTouch2G and it was approved...

    I've found that the app review process is inconsistent at best...

    Chalk another one up for the WTF? pile.

    ;)
    <b><a href="http://www.sdkcoder.com" target="_blank">www.sdkcoder.com</a></b><br />
    <font size="1">Are my posts helping you? Please help support my forum!<br />
    <i>Aiming to be one of the most comprehensive iPhone resources on the net.</i></font>
  • rames44rames44 Posts: 365Tutorial Authors, Registered Users @ @
    edited October 2008
    Alternately, instead of testing for specific device models, you could simply test to see if the camera function is available using
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
    ...
    }
    
    and enable / disable that portion of your UI accordingly. That way you don't have to worry if they release new iPods with different model names or something like that...
    For a little fun, check out my <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=298866985&mt=8" target="_blank">Biorhythms</a> app
  • vigneshvignesh Posts: 4New Users
    edited July 2009
    How to identify the ipod or iphone generations?
  • FalccoFalcco Posts: 31Registered Users
    edited August 2009
    Hi,

    I wanted to use: NSString *device = [[UIDevice currentDevice] model]; for detection on which device is the app installed, but if I try that on iPhone app crash (EXC_BAD_ACCESS), but if I try that on iPod Touch its works OK.
    Know anybody where is the problem?

    or find another way to get if the device has microphone or not. I`m using this part of code now:
    	NSString *device = [[UIDevice currentDevice] model];
    	
    	if([device isEqualToString:@"iPhone"])
    	{
    		//Has microphone
    		[device release];
    		return true;
    	}
    	
    	else if([device isEqualToString:@"iPhone 3G"])
    	{
    		//Has microphone
    		[device release];
    		return true;
    	}
    	
    	else if([device isEqualToString:@"iPhone 3G S"])
    	{
    		//Has microphone
    		[device release];
    		return true;
    	}
    	
    	if([device isEqualToString:@"iPod touch"])
    	{
    		//Doesn't have microphone
    		[device release];		
    		return false;
    	}
    	
    	if([device isEqualToString:@"iPod touch 2G"])
    	{
    		//Doesn't have microphone
    		[device release];
    		return false;
    	}
    	
    	[device release];
    	return false;
    
    
  • FalccoFalcco Posts: 31Registered Users
    edited August 2009
    There are probably something wrong with [device release]. If I deleted this lines with [device release] than its works OK. Can somebody explain to me how its works with the returned NSString object?
  • KalimbaKalimba ¿La Islas Hermosas?Posts: 2,181iPhone Dev SDK Supporter, Registered Users
    edited August 2009
    Falcco wrote: »
    There are probably something wrong with [device release]. If I deleted this lines with [device release] than its works OK. Can somebody explain to me how its works with the returned NSString object?
    You are not allocating the NSString 'device', so you are not responsible for releasing it.
    <a href="http://bit.ly/gAmufK" target="_blank">icon-r-64.png</a> ~~ Word Flurry ~~ <a href="http://itunes.apple.com/us/app/word-flurry/id399660201?mt=8" target="_blank">App Store</a> / <a href="http://bit.ly/bJiK99
  • DutchDutch Posts: 884Registered Users
    edited August 2009
    This is some code I use to determine the specific make/model of the device.


    UIDeviceHardware.h
    #import <Foundation/Foundation.h>
    
    @interface UIDeviceHardware : NSObject 
    
    - (NSString *) platform;
    - (NSString *) platformString;
    
    @end
    

    UIDeviceHardware.m
    #import "UIDeviceHardware.h"
    #include <sys/types.h>
    #include <sys/sysctl.h>
    
    @implementation UIDeviceHardware
    
    - (NSString *) platform{
    	size_t size;
    	sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    	char *machine = malloc(size);
    	sysctlbyname("hw.machine", machine, &size, NULL, 0);
    	NSString *platform = [NSString stringWithCString:machine];
    	free(machine);
    	return platform;
    }
    
    - (NSString *) platformString{
    	NSString *platform = [self platform];
    	if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
    	if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    	if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    	if ([platform isEqualToString:@"iPod1,1"])   return @"iPod Touch 1G";
    	if ([platform isEqualToString:@"iPod2,1"])   return @"iPod Touch 2G";
    	if ([platform isEqualToString:@"i386"])   return @"iPhone Simulator";
    	return platform;
    }
    
    @end
    


    Implementation Code
    	UIDeviceHardware *h=[[UIDeviceHardware alloc] init];
    	NSString *s=[h platformString];
    
  • ghanalupoghanalupo Posts: 133Registered Users
    edited December 2009
    Dutch wrote: »
    This is some code I use to determine the specific make/model of the device.


    UIDeviceHardware.h
    #import <Foundation/Foundation.h>
    
    @interface UIDeviceHardware : NSObject 
    
    - (NSString *) platform;
    - (NSString *) platformString;
    
    @end
    

    UIDeviceHardware.m
    #import "UIDeviceHardware.h"
    #include <sys/types.h>
    #include <sys/sysctl.h>
    
    @implementation UIDeviceHardware
    
    - (NSString *) platform{
    	size_t size;
    	sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    	char *machine = malloc(size);
    	sysctlbyname("hw.machine", machine, &size, NULL, 0);
    	NSString *platform = [NSString stringWithCString:machine];
    	free(machine);
    	return platform;
    }
    
    - (NSString *) platformString{
    	NSString *platform = [self platform];
    	if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
    	if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    	if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    	if ([platform isEqualToString:@"iPod1,1"])   return @"iPod Touch 1G";
    	if ([platform isEqualToString:@"iPod2,1"])   return @"iPod Touch 2G";
    	if ([platform isEqualToString:@"i386"])   return @"iPhone Simulator";
    	return platform;
    }
    
    @end
    


    Implementation Code
    	UIDeviceHardware *h=[[UIDeviceHardware alloc] init];
    	NSString *s=[h platformString];
    

    Excellent post Dutch, just what I was looking for! Thanks
  • thewittthewitt Posts: 180iPhone Dev SDK Supporter, Registered Users
    edited December 2009
    If possible you should really check for features and not for models. This keeps your application working when new products are released, and is a much more solid concept than tracking models and revisions.

    -t
  • DutchDutch Posts: 884Registered Users
    edited December 2009
    thewitt wrote: »
    If possible you should really check for features and not for models. This keeps your application working when new products are released, and is a much more solid concept than tracking models and revisions.

    -t

    Clearly, that's the better solution for most tasks, but the original question asks how to determine the device. I use this code myself. When a user logs in to my app, I simply make a note in a database as to which type of device they are using (more so for marketing purposes). Recording each feature's availability is over-kill (and sort of pointless) for what we want to do.
  • sidalexsidalex Posts: 109Registered Users
    edited November 2010
Sign In or Register to comment.