Access any apps bundle identifier

116 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 best solutions below

0
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)