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];

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

  • 相关阅读:
    ORA01102 cannot mount database in EXCLUSIVE mode
    VC中cl.exe命令参数详解
    (转)LIB和DLL的区别与使用
    (转)DOS循环:bat/批处理for命令详解之一 (史上虽详尽的总结和说明~~)
    常用Win IDE库函数
    (转)Windows下多媒体计时器使用举例
    (转)C++进阶必读书籍
    (转)sql 行专列 列转行 普通行列转换
    VLFeat(1)——SIFT图像特征提取(VC++实现)
    (转)SIFT算法研究
  • 原文地址:https://www.cnblogs.com/vokie/p/5356086.html
Copyright © 2011-2022 走看看