//
//  获取应用程序信息.h
//  IOS笔记
//

一般会用来判断是否有新版本、是否需要强制更新

iOS的版本号,一个叫做Version,一个叫做Build,这两个值都可以在Xcode 中选中target,点击“Summary”后看到。 Version在plist文件中的key是“CFBundleShortVersionString”,和AppStore上的版本号保持一致,Build在plist中的key是“CFBundleVersion”,代表build的版本号,该值每次build之后都应该增加1。这两个值都可以在程序中通过下面的代码获得:

[[[NSBundle mainBundle] infoDictionary] valueForKey:@"key"]


[2]具体实现
代码实现获得应用的Verison号:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]或[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
获得build号:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]



打印出来infoDictionary的内容
    NSLog(@"%@",[[NSBundle mainBundle]infoDictionary]);
{
    BuildMachineOSBuild = 15B42;
    CFBundleDevelopmentRegion = en;
    CFBundleExecutable = "UIApplication\U7684\U4f7f\U7528";
    CFBundleIdentifier = "cn.juzhong.UIApplication---";
    CFBundleInfoDictionaryVersion = "6.0";
    CFBundleInfoPlistURL = "Info.plist -- file:///Users/liuweicheng/Library/Developer/CoreSimulator/Devices/1A2BA12B-DF68-48F4-995A-C6AC2701D3AE/data/Containers/Bundle/Application/1543AEC3-3B92-4282-896E-C3A1D8E99E33/UIApplication%E7%9A%84%E4%BD%BF%E7%94%A8.app/";
    CFBundleName = "UIApplication\U7684\U4f7f\U7528";
    CFBundleNumericVersion = 16809984;
    CFBundlePackageType = APPL;
    CFBundleShortVersionString = "1.0";
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
                                      iPhoneSimulator
                                      );
    CFBundleURLTypes =     (
                            {
                                CFBundleURLName = "";
                            }
                            );
    CFBundleVersion = 1;
    DTCompiler = "com.apple.compilers.llvm.clang.1_0";
    DTPlatformBuild = "";
    DTPlatformName = iphonesimulator;
    DTPlatformVersion = "9.1";
    DTSDKBuild = 13B137;
    DTSDKName = "iphonesimulator9.1";
    DTXcode = 0711;
    DTXcodeBuild = 7B1005;
    LSRequiresIPhoneOS = 1;
    MinimumOSVersion = "9.1";
    NSAppTransportSecurity =     {
        NSAllowsArbitraryLoads = 1;
    };
    UIDeviceFamily =     (
                          1
                          );
    UILaunchStoryboardName = LaunchScreen;
    UIMainStoryboardFile = Main;
    UIRequiredDeviceCapabilities =     (
                                        armv7
                                        );
    UISupportedInterfaceOrientations =     (
                                            UIInterfaceOrientationPortrait,
                                            UIInterfaceOrientationLandscapeLeft,
                                            UIInterfaceOrientationLandscapeRight
                                            );
}




iOS获取AppStore内应用程序信息

参考 apple的文档:www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

具体步骤如下:

1,用 POST 方式发送请求:

http://itunes.apple.com/search?term=你的应用程序名称&entity=software

更加精准的做法是根据 app 的 id 来查找:

http://itunes.apple.com/lookup?id=你的应用程序的ID

/*
AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];

mgr.responseSerializer = [AFJSONResponseSerializer serializer];

mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/javascript"];

NSLog(@"xxx");

//发送POST请求
[mgr POST:@"http://itunes.apple.com/search?term=QQ&entity=software" parameters:nil  success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%@",error);
}];

AFHTTPRequestOperationManager *mgr1 = [AFHTTPRequestOperationManager manager];
mgr1.responseSerializer = [AFJSONResponseSerializer serializer];
mgr1.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/javascript"];
NSLog(@"xxx");
//发送POST请求
[mgr1 POST:@"http://itunes.apple.com/lookup?id=com.tenpay.mobile.iphone" parameters:nil  success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    
    NSLog(@"%@",error);
}];
}
*/