Cocoa: Get Bundle Identifier Programmatically

Sometimes you need to check the bundle identifier (short: bundle id) of your iOS or OSX app programmatically at runtime. For Objective C (ObjC) you can use that code in XCode:

NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
if ([bundleIdentifier isEqualToString:@"com.da.MyAppIdentifier"]) {
    //do some cool stuff here

If you are using Swift the code it looks a little bit different

let bundleIdentifier = NSBundle.mainBundle().bundleIdentifier
if bundleIdentifier == "com.da.MyAppIdentifier" {
    //do some cool stuff here

You can also check out the developer documentation for more detailed information.


comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum