在SO寻找到如何检测用户设备在这里后: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];
}
}
你可以登录machineName()并查看结果是什么? –
您是否尝试在调试器中单步解决问题? –
您可能还需要检查字符串是否包含字符串的第一部分,因为新手机的型号不同。 –