14

How to detect my current device name through iOS?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256

4 Answers4

22

Whether you are on an iPhone or a iPod Touch:

UIDevice *device = [UIDevice currentDevice];
NSString *systemName = [device systemName];

To detect the version of the OS:

UIDevice *device = [UIDevice currentDevice];
NSString *systemVersion = [device systemVersion];

To detect a specific model, you would need to test for some capability that only that model has, so to detect an iPhone 3GS, check for a video capability on the camera:

#define SOURCETYPE UIImagePickerControllerSourceTypeCamera

// does the device have a camera?
if ([UIImagePickerController isSourceTypeAvailable:SOURCETYPE]) {
  // if so, does that camera support video?
  NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:SOURCETYPE];
  bool isA3GS = [mediaTypes containsObject:kUTTypeMovie];
}
mmc
  • 17,354
  • 2
  • 34
  • 52
  • this line shows an error [mediaTypes containsObject:kUTTypeMovie]; error: 'kUTTypeMovie' undeclared – Rahul Vyas Oct 20 '09 at 14:08
  • 5
    Either of the following will fix it. 1) Add the MobileCoreServices framework to your project 2) Add #import to the header file where you will reference the picker. Alternately, you can add the import to your precompiled header file (.pch) so the UTCoreTypes constants are available throughout the project. – mmc Oct 20 '09 at 14:27
  • 2
    in my experience you need to do both 1 and 2. – erich Dec 07 '10 at 17:22
  • 1
    Rahul Vyas: try this [mediaTypes containsObject:(NSString *)kUTTypeMovie] – mrburns05 Feb 16 '11 at 18:34
19

Here is a class written by Erica Sadun that provides extensive capabilities for this:

http://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m

Check out the rest of the repo - there are a few more classes that would prove to be really useful for fine-grained device querying.

jtrim
  • 3,465
  • 4
  • 31
  • 44
  • 1
    This one's even better! Great to be able to retrieve max memory size, etc. Erica Sadun has some very helpful classes. Thanks for linking to this! – Ben Baron Jan 07 '11 at 19:16
9

From the UIDevice.h file:

[[UIDevice currentDevice] name]              // e.g. "My iPhone"
[[UIDevice currentDevice] model]             // e.g. @"iPhone", @"iPod Touch"
[[UIDevice currentDevice] localizedModel]    // localized version of model
[[UIDevice currentDevice] systemName]        // e.g. @"iPhone OS"
[[UIDevice currentDevice] systemVersion]     // e.g. @"2.0"
[[UIDevice currentDevice] uniqueIdentifier]  // a string unique to each device based on various hardware info.
Adolfo
  • 4,969
  • 4
  • 26
  • 28
  • i run my app in 2g iPhone but it return only iPhone not iPhone 2g. here us the code NSString *uniqueIdentifier= [[UIDevice currentDevice] uniqueIdentifier]; NSString* Modal=[[UIDevice currentDevice] localizedModel]; – Rahul Vyas Oct 10 '09 at 08:40
  • you can use [[UIDevice currentDevice] model] – Paresh Thakor Jul 30 '12 at 09:16
0

What you are looking for is this:

UIDevice *device = [UIDevice currentDevice];
NSString *model = [device model];

This will return whether the device is an iPhone or iPod touch

Chandler De Angelis
  • 2,646
  • 6
  • 32
  • 45