HeikoG
HeikoG

Reputation: 1813

getting the name of the application

I have a lite and a full version and want them to work with different configuration Files.

Now I need to query, within the application, if the application name has "lite" in it and load the coresponding config-file I havent found how to do it. Any Idea ? Or is there generally a better approach for that ?

Thanks in advance Heiko

Upvotes: 3

Views: 551

Answers (4)

Krunal
Krunal

Reputation: 79646

Try this for Swift:

if let appName = Bundle.main.infoDictionary?["CFBundleName"] as? String {
    print("App Name - \(appName)")
}

Also try this, if you've set Display Name

if let displayName = Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String {
    print("App Display Name - \(displayName)")
}

Useful trick:

// Print bundle info dictionary to get complete details about app
print("Bundle.main.infoDictionary - \(Bundle.main.infoDictionary)")

Upvotes: 0

Lou Franco
Lou Franco

Reputation: 89172

You application has a main() in main.m (if you used a template). It gets passed the command-line arguments and argv[0] should be the full path of the application, which you can parse. You'll have to save it in a global variable.

You could also check the launchOptions in the appDelegate to see if it's there too.

Upvotes: 2

Dave DeLong
Dave DeLong

Reputation: 243146

If you want what was put into the Info.plist file, use:

NSString * displayName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];

Upvotes: 5

Akash Kava
Akash Kava

Reputation: 39916

Try

[[NSProcessInfo processInfo] processName]

This returns process name, which is usually your application's name.

Upvotes: 3

Related Questions