How to get the name of the running application in iOS

If the application name under the icon on the home screen is "My Awesome App" how do you get that string within the application at runtime?


Solution 1:

I’d try

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];

although presumably you know your own app’s name and can just use it…

Solution 2:

Swift 3 & 4

Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String ?? ""
Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ?? ""


Swift 2.2

NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName")
NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleDisplayName")


More about 'CFBundleName' and 'CFBundleDisplayName'

The following is from Apple's documentation on Core Foundation Keys

CFBundleName, “Bundle name”, The short name of the bundle; not intended to be seen by the user. See CFBundleName for details. (Recommended, Localizable)

CFBundleDisplayName, “Bundle display name”, The user-visible name of the bundle; used by Siri and visible on the Home screen in iOS. See CFBundleDisplayName for details. (Required, Localizable)

Solution 3:

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];

Solution 4:

Just because I love the Xcode 4.5 new way to get an array item. :)

- (NSString*)project_getAppName {
    return NSBundle.mainBundle.infoDictionary[@"CFBundleDisplayName"];
}

Solution 5:

For Xamarin.iOS use:

return ((NSString)NSBundle.MainBundle.InfoDictionary["CFBundleName"]).ToString();