开发者

Objective C: How to get another application's bundle identifier

开发者 https://www.devze.com 2023-02-03 10:30 出处:网络
I would like to get the bundle identifier of an application, given it\'s path. eg: NSString* vlcFilePath =@\"/Applications/VLC.app\"

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

精彩评论

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