Objective C: How to get another application's bundle identifier
I would like to get the bundle identifier of an application, given it's path.
eg:
NSString* vlcFilePath = @"/Applications/VLC.app"
I know how to get the bundle identifier u开发者_运维技巧sing NSWorkspace
if it is the active application, but in this case it is not necessarily the active application.
NSBundle has a bundleIdentifier
method. This won't run or load the application if it is not already loaded/running:
NSString *vlcFilePath = @"/Applications/VLC.app";
NSBundle *bundle = [NSBundle bundleWithPath:vlcFilePath];
NSLog (@"%@", [bundle bundleIdentifier]);
Open the application bundle's plist file and read it from there:
NSDictionary *plistInfo = [NSDictionary dictionaryWithContentsOfFile:[vlcPath stringByAppendingPathComponent:@"Contents/Info.plist"]];
NSLog(@"VLC bundle identifier = %@", [plistInfo objectForKey:@"CFBundleIdentifier"]);
精彩评论