iOS获取APP、设备等信息

获取App的版本号、App的build版本号、包名、App显示名称
/*获取当前App的版本号信息*/
+ (NSString *)getAppVersion{
    NSBundle *currentBundle = [NSBundle mainBundle];
    NSDictionary *infoDictionary = [currentBundle infoDictionary];
    NSString *appVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    return appVersion;
}

/*获取当前App的build版本号信息*/
+ (NSString *)getAppBuildVersion{
    NSBundle *currentBundle = [NSBundle mainBundle];
    NSDictionary *infoDictionary = [currentBundle infoDictionary];
    NSString *appBuildVersion = [infoDictionary objectForKey:@"CFBundleVersion"];
    return appBuildVersion;
}

/*获取当前App的包名信息*/
+ (NSString *)getAppBundleId{
    NSBundle *currentBundle = [NSBundle mainBundle];
    NSDictionary *infoDictionary = [currentBundle infoDictionary];
    NSString *appBundleId = [infoDictionary objectForKey:@"CFBundleIdentifier"];
    return appBundleId;
}

/*获取当前App的包名信息*/
+ (NSString *)getAppDisplayName{
    NSBundle *currentBundle = [NSBundle mainBundle];
    NSDictionary *infoDictionary = [currentBundle infoDictionary];
    NSString *appDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    return appDisplayName;
}
手机系统版本、手机版本
/*设备系统版本
 例如:@"12.3.1"*/
+ (NSString *)deviceSystemVersion{
    UIDevice *device = [UIDevice currentDevice];
    return device.systemVersion;
}

/*设备系统名称
 例如:@"iOS"*/
+ (NSString *)deviceSystemName{
    UIDevice *device = [UIDevice currentDevice];
    return device.systemName;
}

/*设备名称
 例如:@"My iPhone"*/
+ (NSString *)deviceName{
    UIDevice *device = [UIDevice currentDevice];
    return device.name;
    
}

/*设备类型
 例如:@"iPhone", @"iPod touch"*/
+ (NSString *)deviceModel{
    UIDevice *device = [UIDevice currentDevice];
    return device.model;
}

+ (NSString *)deviceStringString{
    // 需要导入  #include 
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString * deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
 /*
    //也可以通过下面的方法获取
    // 需要导入  #import 
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = (char*)malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString * deviceString = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    //*/

    // iphone
    if ([deviceString isEqualToString:@"iPhone1,1"])    return @"iPhone 2G";
    if ([deviceString isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    
    if ([deviceString isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    
    if ([deviceString isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([deviceString isEqualToString:@"iPhone3,2"])    return @"Verizon iPhone 4";
    if ([deviceString isEqualToString:@"iPhone3,3"])    return @"iPhone 4 (CDMA)";
    
    if ([deviceString isEqualToString:@"iPhone4,1"])    return @"iPhone 4S"
        ;
    
    if ([deviceString isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
    if ([deviceString isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";
    if ([deviceString isEqualToString:@"iPhone5,3"])    return @"iPhone 5C (CDMA)";
    if ([deviceString isEqualToString:@"iPhone5,4"])    return @"iPhone 5C";
    
    if ([deviceString isEqualToString:@"iPhone6,1"])    return @"iPhone 5S (CDMA)";
    if ([deviceString isEqualToString:@"iPhone6,2"])    return @"iPhone 5S";
    
    if ([deviceString isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([deviceString isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
    
    if ([deviceString isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
    if ([deviceString isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
    if ([deviceString isEqualToString:@"iPhone8,3"])    return @"iPhone SE";
    if ([deviceString isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
    
    if ([deviceString isEqualToString:@"iPhone9,1"])    return @"iPhone 7";
    if ([deviceString isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus";
    if ([deviceString isEqualToString:@"iPhone9,3"])    return @"iPhone 7";
    if ([deviceString isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus";
    
    if ([deviceString isEqualToString:@"iPhone10,1"])    return @"iPhone 8";
    if ([deviceString isEqualToString:@"iPhone10,2"])    return @"iPhone 8 Plus";
    if ([deviceString isEqualToString:@"iPhone10,3"])    return @"iPhone X";
    if ([deviceString isEqualToString:@"iPhone10,4"])    return @"iPhone 8";
    if ([deviceString isEqualToString:@"iPhone10,5"])    return @"iPhone 8 Plus";
    if ([deviceString isEqualToString:@"iPhone10,6"])    return @"iPhone X";
    
    if ([deviceString isEqualToString:@"iPhone11,2"])    return @"iPhone XS";
    if ([deviceString isEqualToString:@"iPhone11,4"])    return @"iPhone XS Max";
    if ([deviceString isEqualToString:@"iPhone11,6"])    return @"iPhone XS Max";
    if ([deviceString isEqualToString:@"iPhone11,8"])    return @"iPhone XR";

    
    //ipod
    if ([deviceString isEqualToString:@"iPod1,1"])      return @"iPod Touch (1 Gen)";
    if ([deviceString isEqualToString:@"iPod2,1"])      return @"iPod Touch (2 Gen)";
    if ([deviceString isEqualToString:@"iPod3,1"])      return @"iPod Touch (3 Gen)";
    if ([deviceString isEqualToString:@"iPod4,1"])      return @"iPod Touch (4 Gen)";
    if ([deviceString isEqualToString:@"iPod5,1"])      return @"iPod Touch (5 Gen)";
    
    
    //ipad
    if ([deviceString isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([deviceString isEqualToString:@"iPad1,2"])      return @"iPad 3G";
    
    if ([deviceString isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([deviceString isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
    if ([deviceString isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([deviceString isEqualToString:@"iPad2,4"])      return @"iPad 2 (32nm)";
    if ([deviceString isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
    if ([deviceString isEqualToString:@"iPad2,6"])      return @"iPad Mini (GSM)";
    if ([deviceString isEqualToString:@"iPad2,7"])      return @"iPad Mini (GSM+CDMA)";
    
    if ([deviceString isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
    if ([deviceString isEqualToString:@"iPad3,2"])      return @"iPad 3 (GSM+CDMA)";
    if ([deviceString isEqualToString:@"iPad3,3"])      return @"iPad 3 (4G)";
    if ([deviceString isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([deviceString isEqualToString:@"iPad3,5"])      return @"iPad 4 (4G)";
    if ([deviceString isEqualToString:@"iPad3,6"])      return @"iPad 4 (GSM+CDMA)";
    
    if ([deviceString isEqualToString:@"iPad4,1"])      return @"iPad Air";
    if ([deviceString isEqualToString:@"iPad4,2"])      return @"iPad Air";
    if ([deviceString isEqualToString:@"iPad4,3"])      return @"iPad Air";
    if ([deviceString isEqualToString:@"iPad4,4"]
       ||[deviceString isEqualToString:@"iPad4,5"]
       ||[deviceString isEqualToString:@"iPad4,6"])      return @"iPad mini 2";
    if ([deviceString isEqualToString:@"iPad4,7"]
        ||[deviceString isEqualToString:@"iPad4,8"]
        ||[deviceString isEqualToString:@"iPad4,9"])      return @"iPad mini 3";

    if ([deviceString isEqualToString:@"iPad5,1"])       return @"iPad Mini 4 (WiFi)";
    if ([deviceString isEqualToString:@"iPad5,2"])     return @"iPad Mini 4 (LTE)";
    if ([deviceString isEqualToString:@"iPad5,3"])      return @"iPad Air 2";
    if ([deviceString isEqualToString:@"iPad5,4"])      return @"iPad Air 2";
    
    if ([deviceString isEqualToString:@"iPad6,3"])return @"iPad Pro 9.7";
    if ([deviceString isEqualToString:@"iPad6,4"])return @"iPad Pro 9.7";
    if ([deviceString isEqualToString:@"iPad6,7"])return @"iPad Pro 12.9";
    if ([deviceString isEqualToString:@"iPad6,8"])return @"iPad Pro 12.9";
    if ([deviceString isEqualToString:@"iPad6,11"])return @"iPad 5 (WiFi)";
    if ([deviceString isEqualToString:@"iPad6,12"])return @"iPad 5 (Cellular)";
    
    if ([deviceString isEqualToString:@"iPad7,1"])return @"iPad Pro 12.9 inch 2nd gen (WiFi)";
    if ([deviceString isEqualToString:@"iPad7,2"])return @"iPad Pro 12.9 inch 2nd gen (Cellular)";
    if ([deviceString isEqualToString:@"iPad7,3"])return @"iPad Pro 10.5 inch (WiFi)";
    if ([deviceString isEqualToString:@"iPad7,4"])return @"iPad Pro 10.5 inch (Cellular)";
  
    //Simulator
    if ([deviceString isEqualToString:@"i386"])         return @"Simulator";
    if ([deviceString isEqualToString:@"x86_64"])       return @"Simulator";
    return deviceString;
}



struct utsname {
char sysname[_SYS_NAMELEN]; /* [XSI] Name of OS /
char nodename[_SYS_NAMELEN]; /
[XSI] Name of this network node /
char release[_SYS_NAMELEN]; /
[XSI] Release level /
char version[_SYS_NAMELEN]; /
[XSI] Version level /
char machine[_SYS_NAMELEN]; /
[XSI] Hardware type */
};

你可能感兴趣的:(iOS获取APP、设备等信息)