Please consider subscribing to Mobile Developer Tips RSS feed or following us on Twitter
|
|
|
If you ever need to get the name of your application in code, for example, to display the application name across a navigation bar, it’s as near as the bundle for your application.
The code to get the name is as simple as this:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
The breakdown is as follows:
NSBundle mainBundle creates a bundle object that maps to the directory where the application lives.
infoDictionary returns a dictionary that contains the contents of the above bundles Info.plist
objectForKey:@”CFBundleName” will return the value for specified key, in our example, the name of the application.
Read more about Information Property Lists and Key Values
Comments
3 Responses to “Get Application Name”
Leave Comment
Hello,
To my mind the right key is CFBundleDisplayName
[Reply]
John Muchow Reply:
September 5th, 2011 at 9:11 am
Hey Bruno, thanks. I looked up both keys in the Apple docs, for CFBundleName is states: “If you localize this key, you should also include the key “CFBundleDisplayName.” For CFBundleDisplayName “If you localize this key, you should also include a localized version of the CFBundleName key. If you do not intend to localize your bundle, do not include this key in your Info.plist file.” So I guess it really depends on whether or not the app is localized.
[Reply]
infoDictionary returns a dictionary that contains the contents of the above bundles Info.plist
Yes you are right i did try it and works
[Reply]