开发者

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"]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜