I would like to add the current version into the "about" section of my app. As seen in this attached screenshot Apple offers versioning.
我想把当前的版本添加到我的应用程序的“about”部分中,在这个附件截图中,Apple提供了版本控制。
How do you display these settings in your app?
如何在app中显示这些设置?
Screenshot of Target 'myApp' Info http://i35.tinypic.com/30c7ith.jpg
目标“myApp”信息的截图http://i35.tinypic.com/30c7ith.jpg
6 个解决方案
#1
25
After further searching and testing, I found the solution myself.
经过进一步的搜索和测试,我自己找到了解决方案。
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSLog(@"%i Keys: %@", [infoDictionary count],
[[infoDictionary allKeys] componentsJoinedByString: @" ,"]);
This snipplet gave me the following output:
这个剪切输出如下:
20 Keys : NSBundleResolvedPath ,CFBundleVersion ,NSBundleInitialPath ,CFBundleIdentifier ,NSMainNibFile ,CFBundleIconFile ,CFBundleInfoPlistURL ,CFBundleExecutable ,DTSDKName ,UIStatusBarStyle ,CFBundleDevelopmentRegion ,DTPlatformName ,CFBundleInfoDictionaryVersion ,CFBundleSupportedPlatforms ,CFBundleExecutablePath ,CFBundleDisplayName ,LSRequiresIPhoneOS ,CFBundlePackageType ,CFBundleSignature ,CFBundleName
nsmdleresolvedpath,CFBundleVersion,NSBundleInitialPath,CFBundleIdentifier,NSMainNibFile,CFBundleIconFile, cfbundleinflisturl, cfbundkname,UIStatusBarStyle,CFBundleDevelopmentRegion
So the solution is as simple as:
所以解决方法很简单:
NSString *version =[[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"];
However, this is not the Current Project Version as seen in the screenshot but the Bundle Version of the plist file.
但是,这不是屏幕快照中所看到的当前项目版本,而是plist文件的包版本。
#2
12
Look into your Info.plist
file which should have keys like CFBundleVersion
and CFBundleShortVersionString
看看你的信息。plist文件应该有像CFBundleVersion和CFBundleShortVersionString这样的键。
#3
7
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.
这些物品在构建信息不可以建立应用。它们是占位符,你可以拉进你的程序。在你的应用程序是什么,你是什么地方,说,你的应用程序的资源文件夹,就像任何文本文件,或plist,或一个漂亮的照片你版本控制工程师。
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.
现在,您可以将Build Info窗口中的一些项拖放到一个Info中。plist,使用特殊标识符,如${VERSION_INFO_PREFIX}或其他标记。如果单击上面包含的窗口中左侧的任何项,则可以使用令牌。例如,单击单词“当前项目版本”并复制您在底部看到的标记“CURRENT_PROJECT_VERSION”。然后转到plist文件,并添加一个条目。给它任何你想要的名字或“当前项目版本”。在右侧粘贴${CURRENT_PROJECT_VERSION}。现在你可以从你的应用程序中以编程的方式获得这个值。当然,现在必须有人将该值输入到构建信息窗口或其他地方的适当位置。在info中管理这个和这样的字段可能更简单。plist文件。这些事情由你来处理。
Here is how I get version info out of my info.plist:
以下是我如何从我的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;
}
#4
4
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"];
returns me always the same value(initial version) even if i change the version from the project settings but.
返回始终相同的值(初始版本),即使我从项目设置中更改了版本,但是。
NSString * appVersionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
does the trick.
就可以了。
#5
1
For the lazy here is the swift version :
以下是斯威夫特的版本:
NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString")!
#6
1
NSBundle.mainBundle.infoDictionary[@"CFBundleShortVersionString"];
NSBundle.mainBundle.infoDictionary[@“CFBundleShortVersionString”);
#1
25
After further searching and testing, I found the solution myself.
经过进一步的搜索和测试,我自己找到了解决方案。
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSLog(@"%i Keys: %@", [infoDictionary count],
[[infoDictionary allKeys] componentsJoinedByString: @" ,"]);
This snipplet gave me the following output:
这个剪切输出如下:
20 Keys : NSBundleResolvedPath ,CFBundleVersion ,NSBundleInitialPath ,CFBundleIdentifier ,NSMainNibFile ,CFBundleIconFile ,CFBundleInfoPlistURL ,CFBundleExecutable ,DTSDKName ,UIStatusBarStyle ,CFBundleDevelopmentRegion ,DTPlatformName ,CFBundleInfoDictionaryVersion ,CFBundleSupportedPlatforms ,CFBundleExecutablePath ,CFBundleDisplayName ,LSRequiresIPhoneOS ,CFBundlePackageType ,CFBundleSignature ,CFBundleName
nsmdleresolvedpath,CFBundleVersion,NSBundleInitialPath,CFBundleIdentifier,NSMainNibFile,CFBundleIconFile, cfbundleinflisturl, cfbundkname,UIStatusBarStyle,CFBundleDevelopmentRegion
So the solution is as simple as:
所以解决方法很简单:
NSString *version =[[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"];
However, this is not the Current Project Version as seen in the screenshot but the Bundle Version of the plist file.
但是,这不是屏幕快照中所看到的当前项目版本,而是plist文件的包版本。
#2
12
Look into your Info.plist
file which should have keys like CFBundleVersion
and CFBundleShortVersionString
看看你的信息。plist文件应该有像CFBundleVersion和CFBundleShortVersionString这样的键。
#3
7
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.
这些物品在构建信息不可以建立应用。它们是占位符,你可以拉进你的程序。在你的应用程序是什么,你是什么地方,说,你的应用程序的资源文件夹,就像任何文本文件,或plist,或一个漂亮的照片你版本控制工程师。
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.
现在,您可以将Build Info窗口中的一些项拖放到一个Info中。plist,使用特殊标识符,如${VERSION_INFO_PREFIX}或其他标记。如果单击上面包含的窗口中左侧的任何项,则可以使用令牌。例如,单击单词“当前项目版本”并复制您在底部看到的标记“CURRENT_PROJECT_VERSION”。然后转到plist文件,并添加一个条目。给它任何你想要的名字或“当前项目版本”。在右侧粘贴${CURRENT_PROJECT_VERSION}。现在你可以从你的应用程序中以编程的方式获得这个值。当然,现在必须有人将该值输入到构建信息窗口或其他地方的适当位置。在info中管理这个和这样的字段可能更简单。plist文件。这些事情由你来处理。
Here is how I get version info out of my info.plist:
以下是我如何从我的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;
}
#4
4
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"];
returns me always the same value(initial version) even if i change the version from the project settings but.
返回始终相同的值(初始版本),即使我从项目设置中更改了版本,但是。
NSString * appVersionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
does the trick.
就可以了。
#5
1
For the lazy here is the swift version :
以下是斯威夫特的版本:
NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString")!
#6
1
NSBundle.mainBundle.infoDictionary[@"CFBundleShortVersionString"];
NSBundle.mainBundle.infoDictionary[@“CFBundleShortVersionString”);