I moved from Jane

Original address of this article:The original address

One man digs a hole, another fills it… Some background:

App update iteration, need to do a version control update switch with the background. Normally, the version of Xcode corresponds to the version of App Store, and determines whether the switch is enabled based on this value.

But here’s the problem. The last iOS engineer had been using build for version control, and the native Xocde version was much higher than the App Store version.

Let’s start with Version. There are xcode version and App Store version. In theory they should be the same. Easy maintenance.

The version of xcode

Can be achieved by

/ / get the version number nsstrings * versionCode = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
Copy the code

Get from the info.plist file

###App Store version is available via the call interface: itunes.apple.com/lookup?id= you… Call method: post Returns result:

NSArray *array = responseObject[@"results"];
NSDictionary *dict = [array lastObject];
NSLog(@"Current version: %@", dict[@"version"]);
Copy the code

The code is as follows:

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:@"https://itunes.apple.com/lookup?id=414478124" parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSArray *array = responseObject[@"results"];
        NSDictionary *dict = [array lastObject];
        NSLog(@"Current version: %@", dict[@"version"]);
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        NSLog @"Request failed";
    }];
}
Copy the code

Xcode should be the same as the App Store version. Easy maintenance.

Build:

Develop internal test version number, write as many as you like, internal development test number, write as many as you like, preferably do not expose. Because you need to + up every time you pack, it doesn’t work well for version control.

// Get build number: NSString *versionName =[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
Copy the code

The version cannot go down because it is irreversible. I can only go ahead and try to update the larger version to catch up with the version of Xcode, hoping that a few more updates will bring the version back to normal.