获取设备类型/型号

时间:2013-02-05 20:58:26

标签: ios objective-c xcode

在此处了解如何在此处检测用户设备:iOS - How to get device make and model?

我制作了一个快速测试应用,根据设备显示提醒。我没有收到此代码的提醒。我在这里错过了什么/做错了什么?

#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];

     }


  }

1 个答案:

答案 0 :(得分:1)

machine struct utsname字段是机器硬件平台,如果程序在iOS模拟器中运行,则为"x86_64"

只有在真实设备上,您才能获得"iPhone5,1"等字符串。