4

i want to know the user uses the iphone or ipad,if the user uses the iphone i want to open the camera,if he uses the ipad or runs in simulator i want to open the library. how it is possible? how to find the details of devices? how to know current using device by user through xcode?

5 Answers 5

23
NSString *deviceType = [UIDevice currentDevice].model;

if([deviceType isEqualToString:@"iPhone"])
{
     //your code
}
.....

Hope this helps.

EDIT:

See this thread -determine-device-iphone-ipod-touch-with-iphone-sdk .

0
14
[[UIDevice currentDevice].model hasPrefix:@"iPhone"]

Use the "hasPrefix" so that it works in simulator.

11

You should not determine whether there is a camera by looking at the model. This is not future proof - for instance, you would not be supporting the iPad 2's camera.

UIImagePickerController has a special method to determine whether a camera in available:

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType

With sourceType being one of

UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
1
  • I would +1000 if I could. This is the one and only correct solution. But at least I don't have to answer the bug reports from the iPad2 user that can't take photos. Apr 1, 2011 at 12:47
6

Make use of this to identify devices.

// If iPhoneOS is 3.2 or greater then __IPHONE_3_2 will be defined
#ifndef __IPHONE_3_2    

typedef enum {
    UIUserInterfaceIdiomPhone,           // iPhone and iPod touch
    UIUserInterfaceIdiomPad,             // iPad
} UIUserInterfaceIdiom;

#define UI_USER_INTERFACE_IDIOM() UIUserInterfaceIdiomPhone

#endif // ifndef __IPHONE_3_2

but if you want to check if camera is available I think you can make use of UIImagePickerController's static method

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
1
  • Note that the UI_USER_INTERFACE_IDIOM() method is supplied by the system in iOS 3.2 and up. Mar 24, 2011 at 7:29
0

Working on Vaibhav Tekam's answer, I used this

NSString *deviceType = [UIDevice currentDevice].model;


if([deviceType hasPrefix:@"iPhone"])
{
     //your code
}

or

 NSString *deviceType = [UIDevice currentDevice].model;

if([deviceType hasPrefix:@"iPad"])
{
     //your code
}

etc. It's much easier that way as it covers all models.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.