【发布时间】:2013-02-05 20:58:26
【问题描述】:
在查看如何在此处检测用户设备之后: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() 看看结果如何?
-
您是否尝试在调试器中单步解决问题?
-
您可能还想检查字符串是否包含字符串的第一部分,因为新手机将具有不同的型号。
-
@elio.d 登录机器获取 2013-02-05 21:26:05.040 hgfdsa[13188:c07] x86_64
-
Martin R 将不得不进行研究,因为从未听说过它并回复您。 @Scott,罗杰那
标签: ios objective-c xcode