20
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

System InfoとiOSバージョンとAppバージョンの取得

Last updated at Posted at 2014-03-20

##サンプルコード##

###端末情報取得###

systemVersion
+ (NSString *)systemVersion
{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4(Rev A)";
    if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4(CDMA)";
    if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
    if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5";    // GSM
    if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5";    // GSM+CDMA
    if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5C";   // GSM
    if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5C";   // GSM+CDMA
    if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5S";   // GSM
    if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5S";   // GSM+CDMA
    if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
    if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
    if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
    if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
    
    if ([platform isEqualToString:@"iPod1,1"])   return @"iPod Touch 1G";
    if ([platform isEqualToString:@"iPod2,1"])   return @"iPod Touch 2G";
    if ([platform isEqualToString:@"iPod3,1"])   return @"iPod Touch 3G";
    if ([platform isEqualToString:@"iPod4,1"])   return @"iPod Touch 4G";
    if ([platform isEqualToString:@"iPod5,1"])   return @"iPod Touch 5G";
    if ([platform isEqualToString:@"iPod7,1"])   return @"iPod Touch 6th";
    
    if ([platform isEqualToString:@"iPad1,1"])   return @"iPad";
    if ([platform isEqualToString:@"iPad2,1"])   return @"iPad 2 WiFi";
    if ([platform isEqualToString:@"iPad2,2"])   return @"iPad 2 GSM";
    if ([platform isEqualToString:@"iPad2,3"])   return @"iPad 2 CDMA";
    if ([platform isEqualToString:@"iPad2,4"])   return @"iPad 2 CDMAS";
    if ([platform isEqualToString:@"iPad2,5"])   return @"iPad Mini Wifi";
    if ([platform isEqualToString:@"iPad2,6"])   return @"iPad Mini (Wi-Fi + Cellular)";
    if ([platform isEqualToString:@"iPad2,7"])   return @"iPad Mini (Wi-Fi + Cellular MM)";
    if ([platform isEqualToString:@"iPad3,1"])   return @"iPad 3 WiFi";
    if ([platform isEqualToString:@"iPad3,2"])   return @"iPad 3 CDMA";
    if ([platform isEqualToString:@"iPad3,3"])   return @"iPad 3 GSM";
    if ([platform isEqualToString:@"iPad3,4"])   return @"iPad 4 Wifi";
    if ([platform isEqualToString:@"iPad4,1"])   return @"iPad 5 Wifi";
    if ([platform isEqualToString:@"iPad4,2"])   return @"iPad 5 Cellular";
    if ([platform isEqualToString:@"iPad4,4"])   return @"iPad 2 Mini Wifi";
    if ([platform isEqualToString:@"iPad4,5"])   return @"iPad 2 Mini Cellular";
    if ([platform isEqualToString:@"iPad4,7"])   return @"iPad 3 Mini Wifi";
    if ([platform isEqualToString:@"i386"])      return @"Simulator";
    if ([platform isEqualToString:@"x86_64"])    return @"Simulator";
    return @"Unknown";
}

###iOSバージョン取得###

iOSVersion
+ (NSString *)iOSVersion
{
    return [[UIDevice currentDevice] systemVersion];
}

###appバージョン取得###

appVersion
+ (NSString *)appVersion
{
    return [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];
}

##結果出力##
System Info: iPhone 5S iOS: 7.1 app: 1.0.0

端末情報の方は新機種出るたびに追加しなきゃいけないのが邪魔臭い。。これでいいのかな。。。

20
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?