Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain Bundle Identifier programmatically

People also ask

How do I get a bundle identifier?

Open you project with XCode, select the top project item in the project navigator at the left. Then select TARGETS -> General. Bundle Identifier is found under Identity.

What is a bundle identifier?

A bundle ID or bundle identifier uniquely identifies an application in Apple's ecosystem. This means that no two applications can have the same bundle identifier. To avoid conflicts, Apple encourages developers to use reverse domain name notation for choosing an application's bundle identifier.


Objective-C

NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];

Swift 1.2

let bundleIdentifier = NSBundle.mainBundle().bundleIdentifier

Swift 3.0

let bundleIdentifier = Bundle.main.bundleIdentifier

Xamarin.iOS

var bundleIdentifier = NSBundle.MainBundle.BundleIdentifier

[[NSBundle mainBundle] bundleIdentifier];

(documentation)


You may need Core Foundation approach to get the value. ARC example is following:

NSString *value = (__bridge_transfer NSString *)CFDictionaryGetValue(CFBundleGetInfoDictionary(CFBundleGetMainBundle()),
                                                                     (const void *)(@"CFBundleIdentifier"));

To get the bundle identifier programmatically in Swift 3.0:

Swift 3.0

let bundle = Bundle.main.bundleIdentifier

f you are trying to get it programmatically , you can use below line of code :

Objective-C:

NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];

Swift 3.0 :

let bundleIdentifier =  Bundle.main.bundleIdentifier

Updated for latest swift It will work for both iOS and Mac apps.