获取设备类型/型号 [英] Get Device Type/ Model
本文介绍了获取设备类型/型号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此处了解如何检测用户设备: iOS - 如何获取设备制作和型号?
After looking on SO in to how to detect users device here: iOS - How to get device make and model?
我制作了一个快速测试应用程序,根据设备显示警报。我没有收到此代码的提醒。我在这里错过了什么/做错了什么?
I made a quick test app to display an alert depending on device. I get no alert from this code. What am I missing/doing wrong here?
#import "ViewController.h"
#import <sys/utsname.h>
NSString* machineName()
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
@interface ViewController ()
@end
- (IBAction)btn:(id)sender {
if ([machineName() isEqualToString:@"iPhone5,1"]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Checking device iphone5" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
} else if ([machineName() isEqualToString:@"iPhone4,1"]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Checking device iphone4" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
}
推荐答案
struct
的机器
字段是机器硬件平台,如果程序在iOS模拟器中运行,则x86_64
。
The machine
field of struct utsname
is the machine hardware platform and that is "x86_64"
if the program is running in the iOS Simulator.
仅在真实设备上,您将获得字符串如iPhone5,1
。
Only on a real device you will get strings like "iPhone5,1"
.
这篇关于获取设备类型/型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文