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?
Asked
Active
Viewed 2.1k times
5 Answers
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 .

Community
- 1
- 1

Vaibhav Tekam
- 2,344
- 3
- 18
- 27
14
[[UIDevice currentDevice].model hasPrefix:@"iPhone"]
Use the "hasPrefix" so that it works in simulator.

nebulabox
- 430
- 3
- 4
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

Pieter Jongsma
- 3,365
- 3
- 27
- 30
-
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. – Matthias Bauch Apr 01 '11 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

visakh7
- 26,380
- 8
- 55
- 69
-
Note that the UI_USER_INTERFACE_IDIOM() method is supplied by the system in iOS 3.2 and up. – Pieter Jongsma Mar 24 '11 at 07: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.

mylogon
- 2,772
- 2
- 28
- 42