How to find out if it is iphone or ipad?

I want to know that the user uses iphone or ipad, if the user uses iphone, I want to open the camera, if he uses ipad or works in the simulator, I want to open the library. how is this possible? How to find device details? how to learn how to use the device through the user through xcode?

+4
source share
5 answers

You do not have to determine if there is a camera looking at the model. This is not future proof - for example, you will not support the iPad 2 camera.

UIImagePickerController has a special method for determining camera availability:

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType 

Since sourceType is one of

 UIImagePickerControllerSourceTypePhotoLibrary, UIImagePickerControllerSourceTypeCamera, UIImagePickerControllerSourceTypeSavedPhotosAlbum 
+11
source
 NSString *deviceType = [UIDevice currentDevice].model; if([deviceType isEqualToString:@"iPhone"]) { //your code } ..... 

Hope this helps.

EDIT:

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

+23
source
 [[UIDevice currentDevice].model hasPrefix:@"iPhone"] 

Use "hasPrefix" to make it work in the simulator.

+13
source

Use 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 the camera is accessible, I think you can use the static UIImagePickerController method

 + (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType 
+6
source

While working on Vaibhava Tekama'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 .. This is much simpler as it covers all models.

0
source

Source: https://habr.com/ru/post/1345049/


All Articles