在查看如何在此处检测用户设备之后:iOS - 如何获取设备制造商和型号?
我制作了一个快速测试应用程序来根据设备显示警报。我没有从这段代码中得到任何警报。我在这里错过了什么/做错了什么?
#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];
}
}