What Are App IDs and Bundle Identifiers
Every developer new to Cocoa and Swift development needs to become familiar with Apple's lingo and processes. In today's tutorial, I'd like to talk about App IDs and bundle identifiers. What is an App ID? What is a bundle ID? And what's the link between App IDs and bundle IDs?
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.
Let's take Cocoacasts as an example. Every application I build for Cocoacasts has a bundle identifier that starts with
com.cocoacasts, that is, the reverse of the Cocoacasts website. For my company, Code Foundry, I use bundle identifiers that start with
You don't need to own the domain you use for your application's bundle identifier. The domain is only used to ensure the bundle identifier is unique. For example, I could also use
blog.cocoacasts for the applications I build for Cocoacasts even though I don't own
To create a unique bundle identifier, you append the name of the application to the reversed domain, for example,
com.cocoacasts.scribbles. Remember that you choose the bundle identifier. Reverse domain name notation is what Apple recommends and it's a pattern most developers use.
The only requirement is that the bundle identifier is unique. Xcode warns you if you choose a bundle identifier that's already in use by another application. I strongly recommended that you use a bundle identifier that makes sense and that's why most developers stick to reverse domain name notation.
If you're building a suite of applications, then you can use the same approach. Take a look at the following example. The first bundle ID is used for the iOS client of Scribbles whereas the second bundle ID is used for the macOS client of Scribbles.
Developers often confuse App IDs with bundle IDs or, even worse, they think they're the same thing. An App ID represents one or more applications in Apple's system. It consists of two components, a Team ID and a bundle ID search string.
In this example,
ABCDE12345 is the Team ID and
com.cocoacasts.scribbles is the bundle ID search string. The Team ID and the bundle ID search string are separated by a period.
The Team ID is the component you don't need to worry about is. It's generated by Apple and prepended to the bundle ID search string.
What is a bundle ID search string? This question takes us back to bundle identifiers. It's possible to use one App ID for several applications. That's where explicit and wildcard App IDs come into play.
The bundle ID search string of an App ID can match a single application or, by including a wildcard, it can match multiple applications of the same development team. Let me show you an example of each App ID type.
Explicit App ID
As the name implies, an explicit App ID doesn't contain a wildcard. The bundle ID search string matches the bundle identifier of one application.
The Team ID,
ABCDE12345, is generated by Apple for your development team. This isn't something you can or should change. The bundle ID search string,
com.cocoacasts.scribbles, doesn't contain an asterisk. In other words, the bundle ID search string matches the bundle identifier of one application, the application with a bundle identifier of
com.cocoacasts.scribbles. An explicit App ID can only be used for one application.
Wildcard App ID
A wildcard App ID is a bit different in that it can be used for one or more applications. The App ID can be used for every application with a bundle identifier that matches the App ID's bundle ID search string.
The above App ID can be used for several bundle identifiers. The asterisk or wildcard indicates that anything following
com.cocoacasts. can be variable.
com.cocoacasts.scribbles com.cocoacasts.scribbles.ios com.cocoacasts.scribbles.macos
What Are App IDs For
You already know that a bundle identifier uniquely identifies an application in Apple's ecosystem. What is the purpose of an App ID? An App ID links one or more applications from a development team in Apple's system. Why is this important?
Whenever you want to enable a capability or application service for your application, you enable that capability for the App ID your application is linked to. This used to be tedious, requiring a visit to Apple's developer website. Xcode has evolved quite a bit over the years and it takes care of the details most of the time. Let me show you how this works.
App IDs and Capabilities
Setting Up the Project
Fire up Xcode and create a new project based on the Single View App template.
Name the project and set the Organization Identifier using reverse domain name notation. The organization identifier is used to create the first component of the application's bundle identifier. Project's name is appended to the organization identifier to create the bundle identifier. Don't worry. You can change this after setting up the project. For example, I prefer to keep the bundle identifier lowercased.
Once you've created the project, you can see the details of your application in the General tab of the target.
Keep in mind that you can't modify the bundle ID whenever you feel like. Once your application is pushed to Apple's App Store, it's no longer possible to change your application's bundle ID. Choose your bundle ID carefully.
Xcode also shows us the Team ID I mentioned earlier. Notice that you're unable to modify the Team ID. You shouldn't need to worry about this.
Let's say we want to enable iCloud for our application. For that to work, we need to inform Apple that our application needs the iCloud capability.
Years ago, this meant a visit to Apple's developer website, creating an App ID, and flipping a switch. This is no longer necessary. Open the Capabilities tab in Xcode and flip the switch of the iCloud section.
Xcode jumps into action, talks to Apple's developer portal on your behalf, and takes care of the necessary steps.
Xcode shows us what tasks it performed on your behalf. Take a look at the bottom of the iCloud section in the Capabilities tab.
Visiting Apple's Developer Website
Let's make sure everything is set up correctly on Apple's servers. Open a browser and visit Apple's developer website. Click Account and sign in with the Apple ID that's linked to your developer account.
On the left, select Certificates, IDs & Profiles.
From the menu on the left, choose App IDs and look for the App ID Xcode created for us. App IDs generated by Xcode start with the letters XC to indicate that Xcode created those on your behalf.
Click the App ID and inspect its configuration. It gives you an overview of the capabilities and applications services of the App ID in the development and production environments.
Notice that iCloud is enabled because we enabled this capability from within Xcode. Some capabilities and application services are enabled by default, such as Game Center and In-App Purchase.
You can manually configure an App ID through Apple's developer website, and that may be necessary from time to time. For example, you can only link SSL certificates to an App ID for push notifications through the developer website. This isn't possible from within Xcode at the time of writing.
It's important that you take a few moments when you choose the bundle ID of your application. Once your application is in the hands of users, you're unable to make changes to the bundle ID. While this isn't something users pay attention to, you don't want to have a bundle ID that makes no sense. Stick with Apple's guidelines and you should be fine.
Most companies include the company's name in the bundle identifier and that makes sense. But remember that the bundle identifier cannot be modified even if the application changes hands, for example, in the event of an acquisition.
If you're a freelance developer or you run an agency, make sure you don't include your name or that of your company in the bundle identifier. Discuss this with the client and make sure you choose a bundle identifier that makes sense for the project and the owner.