views:

3749

answers:

6

I want to detect my current device name. How do I detect it through iPhone SDK? Also how do I detect if the iPhone doesn't have a SIM inserted?

+14  A: 

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
this line shows an error [mediaTypes containsObject:kUTTypeMovie];error: 'kUTTypeMovie' undeclared
Rahul Vyas
Either of the following will fix it. 1) Add the MobileCoreServices framework to your project 2) Add #import <MobileCoreServices/UTCoreTypes.h> 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
+2  A: 

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
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
+8  A: 

I wrote a short blog post that might be of help:

Determine Device Type - 3G or 3GS / iPod First or Second Generation

John
Very helpful post!
Paulo Ferreira
A: 

How would I LOOP through currentDevice to find ALL the values available there. (So it would list all values... for years to come.)

Bonnie
Karen, you should post your request as a new question, not as a answer to the existing question.
Guillaume
A: 

Please, how do I run this command, am a novice and dont know how to. Thanks for helping.

Oluwaseun
+2  A: 

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