How to display the current project version of my App to the user?

后端 未结 6 1515
遥遥无期
遥遥无期 2020-12-01 13:01

I would like to add the current version into the \"about\" section of my app. As seen in this attached screenshot Apple offers versioning.

How do you display these s

6条回答
  •  难免孤独
    2020-12-01 13:11

    Those items in the Build Info are not available to your built app. They are placeholders that you could possibly pull into your app. What is in your app is anything that you place in, say, the Resources folder of your app, like any text files, or plists, or a nice picture of your versioning engineer.

    Now, you could pull some of the items in the Build Info window into a info.plist, using special identifiers, such as ${VERSION_INFO_PREFIX} or other token. The tokens are available if you click on any of the items on the left hand side in the window you have included above. For example, click on the word "Current Project Version" and copy the token that you see at the bottom, "CURRENT_PROJECT_VERSION". Then go to your plist file, and add an entry. Give it any name you want or "Current Project Version". Paste in ${CURRENT_PROJECT_VERSION} on the right hand side. Now that value is available to you from your app, programmatically. Of course, someone now has to enter that value into the appropriate place either in the Build Info window or elsewhere. It might just be easier just to manage this and fields like this in the info.plist file. It's up to you how you'd like to handle these things.

    Here is how I get version info out of my info.plist:

    + (NSString *) getAppVersionNumber;
    {
        NSString    *myVersion,
                    *buildNum,
                    *versText;
    
        myVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
        buildNum = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
        if (myVersion) {
            if (buildNum)
                versText = [NSString stringWithFormat:@"Version: %@ (%@)", myVersion, buildNum];
            else
                versText = [NSString stringWithFormat:@"Version: %@", myVersion];
        }
        else if (buildNum)
            versText = [NSString stringWithFormat:@"Version: %@", buildNum];
        NSLog(versText);
        return versText;
    }
    

提交回复
热议问题