怎么知道是iphone还是ipad?

发布于 2024-10-26 12:39:39 字数 111 浏览 3 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北城挽邺 2024-11-02 12:39:39
NSString *deviceType = [UIDevice currentDevice].model;

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

希望这有帮助。

编辑:

请参阅此线程 -define-device-iphone-ipod-touch- with-iphone-sdk

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 .

把回忆走一遍 2024-11-02 12:39:39
[[UIDevice currentDevice].model hasPrefix:@"iPhone"]

使用“hasPrefix”,以便它在模拟器中工作。

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

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

顾铮苏瑾 2024-11-02 12:39:39

不应该通过看型号来判断是否有摄像头。这不是面向未来的 - 例如,您不会支持 iPad 2 的摄像头。

UIImagePickerController 有一个特殊的方法来确定相机是否可用:

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType

sourceType 是其中之一

UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum

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
我纯我任性 2024-11-02 12:39:39

利用它来识别设备。

// 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

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
Hello爱情风 2024-11-02 12:39:39

在研究 Vaibhav Tecam 的答案时,我使用了这个

NSString *deviceType = [UIDevice currentDevice].model;


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

 NSString *deviceType = [UIDevice currentDevice].model;

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

等等
这种方式要容易得多,因为它涵盖了所有模型。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文