Access any apps bundle identifier

100 views Asked by At

For my app, I have the user choose the path for a specific application of their computer. From that path (i.e. /Applications/Itunes.app) I would like to get the bundle identifier, and create an NSRunningApplication instance from it ([NSRunningApplication runningApplicationsWithBundleIdentifier:(nonnull NSString *)]; How would I go about getting this bundle identifier?

1

There are 1 answers

0
TheDarkKnight On BEST ANSWER

Use the core foundation function CFBundleGetIdentifier

Create the bundle reference from the path to the bundle with CFURLCreateFromFileSystemRepresentation and call CFBundleCreate

url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, bundlePath, bundleLength, true);
bundle = CFBundleCreate(kCFAllocatorDefault, url);

CFStringRef identifier = CFBundleGetIdentifier(bundle)