How can this be achieved? I would like to get the name so i can display it within an app, without having to change it in code each time i change a name, of course.
How can this be achieved? I would like to get the name so i can display it within an app, without having to change it in code each time i change a name, of course.
Try this
NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
NSString *prodName = [info objectForKey:@"CFBundleDisplayName"];
I had a problem when I localize my application name by using InfoPlist.strings, like
CFBundleDisplayName = "My Localized App Name";
I could not obtain localized application name if I use infoDictionary.
In that case I used localizedInfoDirectory like below.
NSDictionary *locinfo = [bundle localizedInfoDictionary];
A simple way is as follows. Be aware that this returns the name of your app's bundle, which you can change to be different from your app's product name.
// (Swift 5)
static let bundleName = Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as! String
If you need your app to have a different name from the bundle and may change Info.plist, you could do something like the following:
// (Swift 5)
// To use this, include a key and value in your app's Info.plist file:
// Key: ProductName
// Value: $(PRODUCT_NAME)
// By default PRODUCT_NAME is the same as your project build target name, $(TARGET_NAME), but this may be changed.
// If you do so, you may wish to change the CFBundleName value to $(TARGET_NAME) in the Info.plist file.
// PRODUCT_NAME is defined in the target's Build Settings in the Packaging section.
static let productName = Bundle.main.object(forInfoDictionaryKey: "ProductName") as! String
let productName = Bundle.main.infoDictionary?["CFBundleName"] as? String
let displayName = Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String