在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()並查看結果是什麼? –
您是否嘗試在調試器中單步解決問題? –
您可能還需要檢查字符串是否包含字符串的第一部分,因爲新手機的型號不同。 –