How to get the name of a running application in iOS

If the application name under the icon on the main screen is “My Awesome App”, how will you get this line in the application at runtime?

+70
ios xcode uiapplication
Nov 30 2018-11-11T00:
source share
10 answers

Id try

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

although presumably you know your own application name and can just use it ...

+128
Nov 30 2018-11-11T00:
source share

Swift 3 and 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") 


Learn more about CFBundleName and CFBundleDisplayName

The following is Apple's core core documentation documentation.

CFBundleName , "Package Name", Shortened Package Name; not intended for viewing by the user. See CFBundleName for details. (Recommended, localized)

CFBundleDisplayName , " Package Display Name", user-visible package name; used by Siri and displayed on the main screen in iOS. See CFBundleDisplayName for details. (Required, Localized)

+21
01 Sep '16 at 21:23
source share
 [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]; 
+19
Dec 23 '14 at 14:40
source share

Just because I like the new Xcode 4.5 way to get an array element. :)

 - (NSString*)project_getAppName { return NSBundle.mainBundle.infoDictionary[@"CFBundleDisplayName"]; } 
+14
Sep 29 '12 at 15:55
source share

To use Xamarin.iOS:

 return ((NSString)NSBundle.MainBundle.InfoDictionary["CFBundleName"]).ToString(); 
+7
Jan 23 '15 at 0:23
source share
 #include <stdlib.h> // work for iOS and MacOSX and ~23 times faster than get name from bundle NSString *app = [NSString stringWithUTF8String:getprogname()]; 
+4
Feb 10 '16 at 17:34
source share

Swift 3/4

 let appName = Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String 
+4
Jul 07 '17 at 8:51
source share
 NSString* applicationName = [entry objectForKey:(id)kCGWindowOwnerName]; 

Here is a good post with examples of what you are looking for. The OP did not accept anything, which is regrettable, but the answers are helpful.

+3
Nov 30 2018-11-11T00:
source share

Swift 3

 let appName = Bundle.main.infoDictionary?["CFBundleName"] as? String 
+3
Nov 01 '16 at 20:37
source share

Attention :
If you localize the name of your application in another language, you must use the hit code to get a true localized display name:

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

Not the following:

 Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String 
0
Apr 28 '19 at 7:53 on
source share



All Articles