getting the name of the application
I have a lite and a full version a开发者_StackOverflow中文版nd 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
If you want what was put into the Info.plist file, use:
NSString * displayName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
Try
[[NSProcessInfo processInfo] processName]
This returns process name, which is usually your application's name.
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.
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)")
精彩评论