iOS uses version number comparison between local and App Store to realize version update

Keywords: Mobile SSL JSON Javascript

The comparison version number is generally used to realize the function of version update. The pop-up window prompts the user to update or directly jump to the App Store.

Get version information of APP in App Store

Here we use iTunes's lookup interface, provided that you have published it to the App Store.

Get the id of the app in the App Store

  1. App Store searches for < software name >, for example: wechat. After entering the details page, click the share button and click the copy link

  1. Long press the downloaded software, click Share App, click Copy link

Find id in the App Store

Get the version number of the app in the App Store

GET request using AFNetworking, as follows

+ (void)getAppStoreVersionInfoWithResponseBlock:(void (^)(NSDictionary *, NSError *))responseBlock {
    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
    [sessionManager.responseSerializer setAcceptableContentTypes: [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]];
    [sessionManager GET:@"" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSArray *dataArray = responseObject[@"results"];
        if (dataArray.count != 0) {// First determine whether the returned data is empty
            NSDictionary *dict = dataArray.firstObject;
            responseBlock(dict, nil);
        } else {
            NSError *emptyError = [[NSError alloc] initWithDomain:NSStringFromClass(self) code:NetWorkResponseCodeAppearError userInfo:@{NSLocalizedDescriptionKey:@"Content is empty"}];
            responseBlock(nil, emptyError);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        responseBlock(nil, error);

json after success

	"resultCount": 1,
	"results": [{
		"isGameCenterEnabled": false,
		"artworkUrl60": "",
		"artworkUrl512": "",
		"artworkUrl100": "",
		"artistViewUrl": "",
		"screenshotUrls": ["", "", "", "", ""],
		"ipadScreenshotUrls": ["", "", ""],
		"appletvScreenshotUrls": [],
		"advisories": ["frequently/A strong adult/The theme of sexual suggestion"],
		"supportedDevices": ["Watch4-Watch4", "iPhone5s-iPhone5s", "iPadAir-iPadAir", "iPadAirCellular-iPadAirCellular", "iPadMiniRetina-iPadMiniRetina", "iPadMiniRetinaCellular-iPadMiniRetinaCellular", "iPhone6-iPhone6", "iPhone6Plus-iPhone6Plus", "iPadAir2-iPadAir2", "iPadAir2Cellular-iPadAir2Cellular", "iPadMini3-iPadMini3", "iPadMini3Cellular-iPadMini3Cellular", "iPodTouchSixthGen-iPodTouchSixthGen", "iPhone6s-iPhone6s", "iPhone6sPlus-iPhone6sPlus", "iPadMini4-iPadMini4", "iPadMini4Cellular-iPadMini4Cellular", "iPadPro-iPadPro", "iPadProCellular-iPadProCellular", "iPadPro97-iPadPro97", "iPadPro97Cellular-iPadPro97Cellular", "iPhoneSE-iPhoneSE", "iPhone7-iPhone7", "iPhone7Plus-iPhone7Plus", "iPad611-iPad611", "iPad612-iPad612", "iPad71-iPad71", "iPad72-iPad72", "iPad73-iPad73", "iPad74-iPad74", "iPhone8-iPhone8", "iPhone8Plus-iPhone8Plus", "iPhoneX-iPhoneX", "iPad75-iPad75", "iPad76-iPad76", "iPhoneXS-iPhoneXS", "iPhoneXSMax-iPhoneXSMax", "iPhoneXR-iPhoneXR", "iPad812-iPad812", "iPad834-iPad834", "iPad856-iPad856", "iPad878-iPad878", "iPadMini5-iPadMini5", "iPadMini5Cellular-iPadMini5Cellular", "iPadAir3-iPadAir3", "iPadAir3Cellular-iPadAir3Cellular", "iPodTouchSeventhGen-iPodTouchSeventhGen", "iPhone11-iPhone11", "iPhone11Pro-iPhone11Pro", "iPadSeventhGen-iPadSeventhGen", "iPadSeventhGenCellular-iPadSeventhGenCellular", "iPhone11ProMax-iPhone11ProMax"],
		"kind": "software",
		"features": ["iosUniversal"],
		"trackViewUrl": "",
		"trackCensoredName": "WeChat",
		"languageCodesISO2A": ["AR", "ZH", "EN", "FR", "DE", "ID", "IT", "JA", "KO", "MS", "PT", "RU", "ZH", "ES", "TH", "ZH", "TR", "VI"],
		"fileSizeBytes": "273698816",
		"sellerUrl": "",
		"contentAdvisoryRating": "17+",
		"averageUserRatingForCurrentVersion": 4.0,
		"userRatingCountForCurrentVersion": 74205,
		"trackContentRating": "17+",
		"currentVersionReleaseDate": "2019-09-25T03:13:08Z",
		"releaseNotes": "This update:\n- Some known problems have been solved.\n\n Last update:\n- You can set the favorite notes, file preview and other pages as floating windows.",
		"isVppDeviceBasedLicensingEnabled": true,
		"primaryGenreName": "Social Networking",
		"genreIds": ["6005", "6007"],
		"primaryGenreId": 6005,
		"sellerName": "Tencent Technology (Shenzhen) Company Limited",
		"releaseDate": "2011-01-21T01:32:15Z",
		"trackId": 414478124,
		"trackName": "WeChat",
		"formattedPrice": "Free Admission",
		"minimumOsVersion": "9.0",
		"currency": "CNY",
		"version": "7.0.8",
		"wrapperType": "software",
		"artistId": 614694882,
		"artistName": "WeChat",
		"genres": ["Social contact", "efficiency"],
		"price": 0.00,
		"description": "Wechat is a full range of mobile communication applications to help you easily connect with friends around the world. Wechat can group chat, video chat, play games with friends, and share their own\n Living in a circle of friends makes you feel a new mobile lifestyle.\n\n  Why use wechat:\n  • Multimedia message: support sending video, picture, text and voice messages.\n  • Group chat and call: set up a group chat of up to 500 people and a real-time video chat of up to 9 people.\n  • Voice and video chat: provide high quality calls around the world.\n  • Expression store: a large number of dynamic expressions, including popular cartoon characters and movies, make chatting more vivid and interesting.\n  • Circle of friends: share every wonderful moment with your friends and record your life.\n  • Privacy protection: strictly protect the privacy of users, which is the only one through TRUSTe Certified real-time communication application.\n  • Meet new friends: get to know new friends through "radar plus friends", "people nearby" and "shake".\n  • Real time location sharing: share geographical location with friends without telling each other through language.\n  • Multilingual: support more than 20 language interfaces, and support message translation in multiple languages.\n  • Wechat campaign: support access Apple Watch And health app Data can be compared with friends on the step ranking. If you need to use it, you can set the-currency-Enabled in accessibility. \n  • More functions: Support cross platform, chat room wallpaper customization, message reminder, custom and public number service.",
		"bundleId": "",
		"averageUserRating": 4.5,
		"userRatingCount": 5041979

You can use Postman to call first, and then write the data model according to your own needs. After obtaining the result, you can directly retrieve the version number "version" in the App Store: "7.0.8".

Comparison between local version number and App Store version number

Take wechat as an example. Clicking the version update button of any version (lower than, higher than or equal to the App Store version) will jump to the App Store. My rule is to make a pop-up window of version information.

Get local version number

  1. To obtain App information, you need to retrieve the information contained in Info.plist.
//A dictionary, constructed from the bundle's Info.plist file, that contains information about the receiver.
- (NSDictionary<NSString *, id> *)appInfoDictionary {
    return [[NSBundle mainBundle] infoDictionary];
  1. Take out version number
- (NSString *)appVersion {
    return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];


Most version numbers are 1.0.0, so you need to take out each bit for comparison.

I used to use the for in loop. After referring to the + compareSystemVersion: toVersion: Method in QMUIKit, I think the while loop is more suitable. The code is as follows

+ (NSComparisonResult)compareSystemVersion:(NSString *)currentVersion toVersion:(NSString *)targetVersion {
    NSArray *currentVersionArr = [currentVersion componentsSeparatedByString:@"."];
    NSArray *targetVersionArr = [targetVersion componentsSeparatedByString:@"."];
    NSInteger pos = 0;
    while ([currentVersionArr count] > pos || [targetVersionArr count] > pos) {
        NSInteger v1 = [currentVersionArr count] > pos ? [[currentVersionArr objectAtIndex:pos] integerValue] : 0;
        NSInteger v2 = [targetVersionArr count] > pos ? [[targetVersionArr objectAtIndex:pos] integerValue] : 0;
        if (v1 < v2) {
            return NSOrderedAscending;
        else if (v1 > v2) {
            return NSOrderedDescending;
    return NSOrderedSame;

Version update full code

- (void)p_versionUpdateButtonAction  {
	//Get local App version number
    NSString *appVersion = [VPUtilityTool sharedInstance].appVersion;
    [VPMineRequestHandler getAppStoreVersionInfoWithResponseBlock:^(NSDictionary * _Nonnull response, NSError * _Nonnull error) {
        if (error) {
		//Jump to the App Store details page
            [UIApplicationInstance vp_openUrlString:@""];
        } else {
            NSString *appStoreVersion = response[@"version"];
            NSComparisonResult comparisonResult = [QMUIHelper compareSystemVersion:appVersion toVersion:appStoreVersion];
			//Pop up only if the result is higher than the local version
            if (comparisonResult == NSOrderedAscending) {
		//Update pop-up
                [AppAlertViewController showWithTitle:@"Version update" content:[NSString stringWithFormat:@"Latest version found: V%@\n succeed in inviting sb. App Store Download updates!", appStoreVersion] cancelButtonTitle:@"cancel" confirmButtonTitle:@"To update" actionsHandlerBlock:^(BOOL isCancel) {
                    if (!isCancel) {
                        [UIApplicationInstance vp_openUrlString:@""];
            } else {
                [UIApplicationInstance vp_openUrlString:@""];

There are so many functions of the version update.

Posted by Shazbot! on Wed, 06 Nov 2019 03:10:04 -0800