How to get the name of the running application in iOS

IosXcodeUiapplication

Ios Problem Overview


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?

Ios Solutions


Solution 1 - Ios

I’d try

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

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

Solution 2 - Ios

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 - Ios

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

Solution 4 - Ios

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 - Ios

For Xamarin.iOS use:

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

Solution 6 - Ios

#include <stdlib.h>

// work for iOS and MacOSX and ~23 times faster than get name from bundle
NSString *app = [NSString stringWithUTF8String:getprogname()];


Solution 7 - Ios

Swift 3, 4, & 5

let appName = Bundle.main.infoDictionary?["CFBundleName"] as? String

Solution 8 - Ios

Swift 3/4

let appName =  Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String

Solution 9 - Ios

NSString* applicationName = [entry objectForKey:(id)kCGWindowOwnerName];

Here is a good post with examples of what you are looking for. The OP didn't accept anything, which is unfortunate, but the answers are useful.

Solution 10 - Ios

Attention:

If you do a localizations in your app, you should use the blew code to get the true localized display name:

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

rather than:

Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJonathanView Question on Stackoverflow
Solution 1 - IosDavid DunhamView Answer on Stackoverflow
Solution 2 - IosMobile DanView Answer on Stackoverflow
Solution 3 - Iosuser4297313View Answer on Stackoverflow
Solution 4 - IosFranckView Answer on Stackoverflow
Solution 5 - IosKraig McConaghyView Answer on Stackoverflow
Solution 6 - IosRoman SolodyashkinView Answer on Stackoverflow
Solution 7 - IosmonkeeView Answer on Stackoverflow
Solution 8 - IosJessView Answer on Stackoverflow
Solution 9 - IosBilly CooverView Answer on Stackoverflow
Solution 10 - IosyuanjileeView Answer on Stackoverflow