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

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

  • 相关阅读:
    android 开发中java.lang.verifyerror问题
    android 获取当前系统及应用信息(一)
    Android排错:has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added here
    Android 自定义menu(一)
    产品经理的技术之痛
    内容营销11金规
    剑指Offer:名企面试官精讲典型编程题
    内容营销——网络营销的杀手级武器
    产品经理应该具有的几个工作态度
    产品经理如何提升自己的知识
  • 原文地址:https://www.cnblogs.com/vokie/p/5356086.html
Copyright © 2011-2022 走看看