Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何知道是iphone还是ipad?_Iphone_Xcode_Ipad_Uiimagepickercontroller_Device - Fatal编程技术网

如何知道是iphone还是ipad?

如何知道是iphone还是ipad?,iphone,xcode,ipad,uiimagepickercontroller,device,Iphone,Xcode,Ipad,Uiimagepickercontroller,Device,我想知道用户使用iphone或ipad,如果用户使用iphone,我想打开相机,如果用户使用ipad或在模拟器中运行,我想打开库。这怎么可能? 如何查找设备的详细信息? 如何通过xcode了解用户当前使用的设备 NSString *deviceType = [UIDevice currentDevice].model; if([deviceType isEqualToString:@"iPhone"]) { //your code } ..... 希望这有帮助 编辑: 请参阅此线程

我想知道用户使用iphone或ipad,如果用户使用iphone,我想打开相机,如果用户使用ipad或在模拟器中运行,我想打开库。这怎么可能? 如何查找设备的详细信息? 如何通过xcode了解用户当前使用的设备

NSString *deviceType = [UIDevice currentDevice].model;

if([deviceType isEqualToString:@"iPhone"])
{
     //your code
}
.....
希望这有帮助

编辑:


请参阅此线程-。

利用此线程识别设备

// 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
但如果你想检查摄像机是否可用,我想你可以使用UIImagePickerController的静态方法

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType

您不应该通过查看模型来确定是否存在摄影机。这不是未来的证明——例如,你不会支持iPad2的摄像头

UIImagePickerController有一种特殊的方法来确定摄像机是否可用:

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
sourceType是其中之一

UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum

使用“hasPrefix”使其在模拟器中工作。

在处理Vaibhav Tekam的答案时,我使用了这个

NSString *deviceType = [UIDevice currentDevice].model;


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

等等。
这样做容易得多,因为它涵盖了所有型号。

注意,iOS 3.2及更高版本中的系统提供了UI\u USER\u INTERFACE\u Stimog()方法。如果可以,我会+1000。这是唯一正确的解决方案。但至少我不必回答iPad2用户无法拍照的错误报告。
NSString *deviceType = [UIDevice currentDevice].model;


if([deviceType hasPrefix:@"iPhone"])
{
     //your code
}
 NSString *deviceType = [UIDevice currentDevice].model;

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