ios - 获取设备类型/型号

标签 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];

     }


  }

最佳答案

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

只有在真实设备上,您才会得到像 "iPhone5,1" 这样的字符串。

关于ios - 获取设备类型/型号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14716754/

相关文章:

javascript - iOS 键盘使用 Phonegap 调整屏幕大小

ios - 处理 UILabel 中的触摸事件并将其连接到 IBAction

objective-c - NSCalibrateBlackColorSpace 的未弃用替代品?

ios - 快速地,我如何缩放和定位 SKSpriteNode 以适合每部 iPhone?

objective-c - 如何在 Xcode4 中构建 Droplet 应用程序?

ios - 每个 TableViewCell 的 IBAction 不返回唯一的 NSIndexPath

ios - PushViewController 在 iOS 5 中无法工作,但在 iOS6 中工作正常

objective-c - iOS UITextView 中的字距调整

objective-c - cocoa中能否判断操作系统是否运行在虚拟机中?

objective-c - 初始化错误中的类型不兼容