Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect the specific iPhone/iPod touch model [duplicate]

Possible Duplicate:
Determine device (iPhone, iPod Touch) with iOS

I am making a game that utilizes the peer-to-peer bluetooth capabilities of the iPhone (and probably the iPod touch 2nd generation). However, to stop the users from trying to play a multiplayer on an iPod 1st gen and iPhone 2G I need to check for the specific device model.

[[UIDevice currentDevice] model] will only tell me if the device is an "iPhone" or an "iPod touch". Is there a way to check for the specific device model, like: "iPhone 3GS", "iPod touch 1st generation" or something.

EDIT:

There is a category to UIDevice (I think it's created by Erica Sadun, I don't take credit for it) that uses the following code to get the specific device model. You can find the whole category here along with other useful stuff: https://github.com/erica/uidevice-extension

#include <sys/types.h> #include <sys/sysctl.h>  @implementation UIDevice (Hardware)  /*  Platforms  iPhone1,1 -> iPhone 1G  iPhone1,2 -> iPhone 3G   iPod1,1   -> iPod touch 1G   iPod2,1   -> iPod touch 2G  */  - (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 encoding:NSUTF8StringEncoding];   free(machine);   return platform; } 

This works and apps using this have been lately approved in the AppStore.

like image 857
Dimitris Avatar asked Jul 10 '09 10:07

Dimitris


People also ask

How do I find my iPhone with an iPod?

Look for your device on a map To find your device, sign in to iCloud.com/find. Or use the Find My app on another Apple device that you own. If your iPhone, iPad, or iPod touch doesn't appear in the list of devices, Find My was not turned on. But you can still protect your account if Find My was not turned on.

How do you find a lost iPod touch when it's offline?

Sign in to icloud.com/find on a Mac or PC, or use the Find My iPhone app on another iPhone, iPad, or iPod touch. Find your device. Open Find My iPhone, and select a device to view its location on a map. If the device is nearby, you can have it play a sound to help you or someone nearby find it.

How do I set up Find My iPod?

To set up Find My on your iPhone, iPad, iPod touch, Mac, or Apple Watch, sign in to the device with your Apple ID, turn on location sharing, and turn on Find My [device]. You need to set up Find My before the device is lost.


2 Answers

You can get the device model number using uname from sys/utsname.h. For example:

#import <sys/utsname.h>  NSString* machineName() {     struct utsname systemInfo;     uname(&systemInfo);      return [NSString stringWithCString:systemInfo.machine                               encoding:NSUTF8StringEncoding]; } 

The result should be:

 @"i386"      on the simulator @"iPod1,1"   on iPod Touch @"iPod2,1"   on iPod Touch Second Generation @"iPod3,1"   on iPod Touch Third Generation @"iPod4,1"   on iPod Touch Fourth Generation @"iPhone1,1" on iPhone @"iPhone1,2" on iPhone 3G @"iPhone2,1" on iPhone 3GS @"iPad1,1"   on iPad @"iPad2,1"   on iPad 2 @"iPad3,1"   on iPad 3 (aka new iPad) @"iPhone3,1" on iPhone 4 @"iPhone4,1" on iPhone 4S @"iPhone5,1" on iPhone 5 @"iPhone5,2" on iPhone 5 
like image 116
Will Harris Avatar answered Oct 10 '22 05:10

Will Harris


Most complete UIDevice (Hardware) category probably is http://github.com/erica/uidevice-extension/ (by Erica Sadun):

[[UIDevice currentDevice] platformType]   // ex: UIDevice4GiPhone [[UIDevice currentDevice] platformString] // ex: @"iPhone 4G" 
like image 40
djromero Avatar answered Oct 10 '22 05:10

djromero