【iOS】获取应用版本和语言

来源:互联网 发布:linux mesg 编辑:程序博客网 时间:2024/06/05 09:11

一.获取应用版本

方式一:通过APPID获取

这种方式需要使用的应用的ID号,从网络获取.

/** *  获取版本号 * *  @param block 获取成功时,返回版本号 *  @param err   网络错误时执行的回调 */+(void)getVersion:(strBlock)block err:(errBlock)err{    NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APP_STORE_ID];    // APP_STORE_TD  应用的ID号    //网络管理者对象    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];    manager.responseSerializer = [AFHTTPResponseSerializer serializer];        //发送GET请求    [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];        if (dic[@"results"][0][@"version"]) {            block(dic[@"results"][0][@"version"]);//获取版本号        }    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {        err();    }];}

方式二:本地获取

    // 获取应用版本    NSString *version =  [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];    NSLog(@"%@",[[NSBundle mainBundle] infoDictionary]);    NSLog(@"应用版本: %@",version);

2015-12-14 11:32:55.857 MVC[27108:1935670] {

    BuildMachineOSBuild = 15B42;

    CFBundleDevelopmentRegion = en;

    CFBundleExecutable = MVC;

    CFBundleIdentifier = "zhuming3834.sina.com";

    CFBundleInfoDictionaryVersion = "6.0";

    CFBundleInfoPlistURL = "Info.plist -- file:///Users/myhg/Library/Developer/CoreSimulator/Devices/B18BEA3B-03D9-45D1-A892-3E7E182DC345/data/Containers/Bundle/Application/91DB3FC8-01B0-4D8B-B52D-559C798B3B68/MVC.app/";

    CFBundleName = MVC;

    CFBundleNumericVersion = 16809984;

    CFBundlePackageType = APPL;

    CFBundleShortVersionString = "1.0"; // 版本号

    CFBundleSignature = "????";

    CFBundleSupportedPlatforms =     (

        iPhoneSimulator

    );

    CFBundleVersion = 1;

    DTCompiler = "com.apple.compilers.llvm.clang.1_0";

    DTPlatformBuild = "";

    DTPlatformName = iphonesimulator;

    DTPlatformVersion = "9.1";

    DTSDKBuild = 13B137;

    DTSDKName = "iphonesimulator9.1";

    DTXcode = 0711; // Xcode版本

    DTXcodeBuild = 7B1005;

    LSRequiresIPhoneOS = 1;

    MinimumOSVersion = "9.1"; //iOS版本

    UIDeviceFamily =     (

        1

    );

    UILaunchStoryboardName = LaunchScreen;

    UIMainStoryboardFile = Main;

    UIRequiredDeviceCapabilities =     (

        armv7

    );

    UISupportedInterfaceOrientations =     ( // 横竖屏

        UIInterfaceOrientationPortrait,

        UIInterfaceOrientationLandscapeLeft,

        UIInterfaceOrientationLandscapeRight

    );

}

2015-12-14 11:32:55.857 MVC[27108:1935670] 应用版本: 1.0

二.获取应用语言

    // 当前所在地信息  NSLocaleIdentifier    NSString *identifier = [[NSLocale currentLocale] localeIdentifier];    NSString *displayName = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:identifier];    NSLog(@"展示语言: %@", displayName);        // 当前所在地的使用语言    NSLocale *currentLocale = [NSLocale currentLocale];    NSLog(@"当前语言: %@", [currentLocale objectForKey:NSLocaleLanguageCode]);        // 系统语言    NSArray *languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];    NSLog(@"系统支持的语言: %@",languages); //系统支持的语言    NSString *locLang = [languages objectAtIndex:0]; // 当前语言    NSLog(@"当前语言: %@",locLang);

2015-12-14 11:32:55.855 MVC[27108:1935670] 展示语言: 中文(简体、美国)

2015-12-14 11:32:55.856 MVC[27108:1935670] 当前语言: zh

2015-12-14 11:32:55.856 MVC[27108:1935670] 系统支持的语言: (

    "zh-Hans-US",

    "en-US"

)

2015-12-14 11:32:55.856 MVC[27108:1935670] 当前语言: zh-Hans-US



0 0