Ana*_*and 4 iphone xcode device uiimagepickercontroller ipad
我想知道用户使用iphone或ipad,如果用户使用iphone我想打开相机,如果他使用ipad或在模拟器中运行我想打开库.怎么可能?如何查找设备的详细信息?如何通过xcode了解用户使用设备的当前情况?
Vai*_*kam 23
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"])
{
//your code
}
.....
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
编辑:
看到这个线程 - 确定设备-iphone-ipod-touch-with-iphone-sdk.
小智 13
[[UIDevice currentDevice].model hasPrefix:@"iPhone"]
Run Code Online (Sandbox Code Playgroud)
使用"hasPrefix"使其在模拟器中工作.
Pie*_*sma 11
您不应该通过查看模型来确定是否有相机.这不是未来的证明 - 例如,你不会支持iPad 2的相机.
UIImagePickerController有一个特殊的方法来确定相机是否可用:
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
Run Code Online (Sandbox Code Playgroud)
sourceType是其中之一
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
Run Code Online (Sandbox Code Playgroud)
利用它来识别设备.
// 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
Run Code Online (Sandbox Code Playgroud)
但如果你想检查相机是否可用,我想你可以使用UIImagePickerController的静态方法
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
Run Code Online (Sandbox Code Playgroud)