zoukankan      html  css  js  c++  java
  • 【iOS】程序中获取应用的信息

    iOS应用中,经常使用到一些程序自身的参数设定,故记录一笔。

    1 //Build号
    2 NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    3 //Version号
    4 NSString *shortVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    5 //bundle id
    6 NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];

    看到这里,似乎明白了,其实上面的key就是App里面的info.plist的一些key。可以打开info.plist文件,然后根据你的需要获取对应的键值。

    常见的罗列下:

     1 //设备名称:iPhone Simulator
     2 NSString *strName = [[UIDevice currentDevice] name];
     3 NSLog(@"设备名称:%@", strSysName);
     4 
     5 //系统名称:iPhone OS
     6 NSString *strSysName = [[UIDevice currentDevice] systemName];
     7 NSLog(@"系统名称:%@", strSysName);
     8 
     9 //系统版本号:9.2
    10 NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];
    11 NSLog(@"系统版本号:%@", strSysVersion);
    12 
    13 //设备模式:iPhone
    14 NSString *strModel = [[UIDevice currentDevice] model];
    15 NSLog(@"设备模式:%@", strModel);
    16 
    17 //本地设备模式:iPhone
    18 NSString *strLocModel = [[UIDevice currentDevice] localizedModel];
    19 NSLog(@"本地设备模式:%@", strLocModel);
    20 
    21 //获取用户语言偏好
    22 //语言:en-US
    23 NSArray *languageArray = [NSLocale preferredLanguages];
    24 NSString *language = [languageArray objectAtIndex:0];
    25 
    26 //国家:en_US
    27 NSLocale *locale = [NSLocale currentLocale];
    28 NSString *country = [locale localeIdentifier];
    29 
    30 //获取设备的唯一标示符
    31 //468585AB-D694-46D0-A6E1-354714E8E23B
    32 NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

    还有包括网络类型的判断,电池电量的获取等等。但不常用,故不收录。

  • 相关阅读:
    cf492D Vanya and Computer Game
    cf492C Vanya and Exams
    cf492A Vanya and Cubes
    bzoj2038 [2009国家集训队]小Z的袜子(hose)
    bzoj3781 小B的询问
    bzoj1858 [Scoi2010]序列操作
    bzoj1060 [ZJOI2007]时态同步
    算法学习心得
    bzoj1054 [HAOI2008]移动玩具
    bzoj3437 小P的牧场
  • 原文地址:https://www.cnblogs.com/vokie/p/5356086.html
Copyright © 2011-2022 走看看