getting the name of the application

493 views Asked by At

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

4

There are 4 answers

0
Akash Kava On BEST ANSWER

Try

[[NSProcessInfo processInfo] processName]

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

1
Lou Franco On

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.

0
Dave DeLong On

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

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

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)")