In this chapter we go beyond the initial Xcode setup that most first-time developers experience to the point where we can build apps for sale and distribution. I’ll walk you through the step-by-step process of creating and downloading certificates, setting up devices, app naming, and provisioning required for you to begin creating sellable apps for the Apple App Store . While most of the time it’s so much simpler just to use the simulator and avoid all the hassles of working with devices, you’ll find that you don’t want to go too far down that road. What generally happens with newer developers is that the simulators provide a “crutch” that makes many of the real-world problems transparent. Things just tend to work more often, and there’s this attitude of, “When I have it perfect, I’ll convert it to an App Store product.” This does work, of course, but there are so many issues and details you have to take care of that the momentum starts to wane. You become more mired in the details of this app name or that profile or something else, and what’s important, the app itself, moves to the background. I’d rather see you work through all this so it’s second nature and you can build device-based apps from the start.
First, I want to warn you that this chapter is very dry reading. Because we cover the essentials of how to do specific, necessary steps, I wrote this in a very procedural manner; e.g., do this, then do this, you should see this, click that, and so on. Boring! But necessary. I love to cook and frequently get a new slow cooker or pasta maker, but do I read the manuals? Not likely. I tend to take off and just try something to see how it works. You can, and many people do, work that way in setting up Xcode. Most of the time, however, you will head down the wrong path; there are just too many options where you can go wrong. It’s usually possible to back out with only minor effects. The most common mistake people make in this phase is using their ideal app name, making too many errors, and having to start over only to find that because they’ve already entered the name into the development system it’s in there permanently. They wind up having to come up with a new name. So, while it’s not that much fun, we just have to wade our way through it all to reach the good stuff.
Let’s get started.
Note
Starting with Xcode 7.1, Apple no longer requires you to purchase a developer license, typically $99USD, to load and test your app with actual device hardware. However, at the time of this writing you still need to have a purchased license in order to sell apps in the App Store as well as to distribute them for beta testing using TestFlight. We’ll proceed in this chapter as if you fully intend to develop for the App Store.
Joining The Apple Developer Program
Problem
You want to distribute your iOS app, but your Xcode distribution is not set up to let you do so.
Solution
You must join the Apple Developer Program for $99USD per year to get access to the resources needed for app distribution.
How It Works
First, go to the most current Apple Developer Programs website using a search engine , since from time to time Apple may change the actual URL of the site. You should see options for enrolling as either an individual or an organization.
Note
Prior to the summer of 2015, Apple offered separate developer programs for iOS and Macintosh OS X. This meant you had to purchase, for $99USD each, different accounts if you wanted to do both iOS and Mac software. Now, one program membership, for one $99USD yearly fee, gives you complete access to both sets of resources.
This is where you want to do a little bit of thinking before you proceed and is why I spent so much time in Chapter 2 discussing career options and the various requirements of your intended path. The most common thing that happens here is that, because it’s so easy, most people just go with an individual developer account to quickly get started. What this means is that you’re developing, distributing, and selling your apps under your own name, not your company name. Much of the time this works out just fine. But if you want to have a company and use your organization’s name on the App Store , you really want to look into enrolling as an organization; that is, use your business name.
It doesn’t cost any more than enrolling as an individual, and you get a few benefits when working this way. In addition to using your business name on the App Store and selling your fantastic and unique creations as a business, you can have additional developers work under your account. So, if you and your friends want to develop apps together, things become much easier. You all work under the same Apple portal using the same sets of certificates, app IDs, and so on. Your team doesn’t even have to use the same email domain. In a typical company, everyone would have an email address such as [email protected] or [email protected]. The names would be different but the <something>.com would all be the same. But if you’re a bunch of people that just want to work together to create something really cool, you probably want to use your personal email addresses. By enrolling as a company you can still do this. In fact, this is how I’ve set up the developer account with which we will be working through the course of this book. My friends and teammates work under my umbrella account but use their own individual email addresses for access.
Note
A common source of confusion when setting up a business-based developer account arises when you try to enroll for the enterprise developer program (Figure 3-1). This is used for companies, typically larger companies, that need to distribute apps to employees within their organization. A common use would be to distribute a product catalog app to the entire sales team. This program costs $299USD.
Figure 3-1. The Apple Developer Enterprise Program is for companies that distribute apps internally as opposed to or in addition to in the App Store . You do not need to join this program to develop apps under your own organizational structure
Individual Enrollment
Joining as an individual is pretty straightforward. You only need enter your legal name, address details, and payment information. You typically get taken to the Apple Store and can complete the purchase using your existing account information. Generally, in moments to at most an hour you’ll receive a couple of emails. The first will be your purchase confirmation—your receipt for the purchase. Later, you’ll receive another email with a link that activates your developer account. In some cases, Apple may have to verify the information you provided. This might happen if, say, your zip code doesn’t match, anything was entered incorrectly, or, like me, you have to enter whether you live within or outside town limits.
Organizational Enrollment
Joining the developer program as a company means you have to fill in a few more details and have the information ready and available. The most important thing is that if joining as a company, you have to have a real company. This can’t just be the name you came up with and put on your business cards; your company’s name should be registered in the state where it was formed.
Most states make forming a company such as a Limited Liability Company pretty easy, but check out all the details and requirements as appropriate. The best advice would be to spend some money to talk with a business attorney and then decide on which type of organization you should form. There are different tax and reporting requirements for each. Once the company is formed, it may take a few days to weeks to have it show up in your state’s registry. In my case it showed up on the same day, but I suspect this varies by region.
Registering your business’s legal name is only one-half of the equation. You also need to have a DUNS number. This is a nine-digit number provided by Dun & Bradstreet. Filing the legal documentation for your business does not automatically provide you with a DUNS number. You will have to do this yourself and provide the following information:
Legal name
Headquarters name and address for your business
Doing Business As (DBA) or other name by which your business is commonly recognized
Physical address, city, state, and zip code
Mailing address (if separate from headquarters and/or physical address)
Telephone number
Contact name and title
Number of employees at your physical location
Whether you are a home-based business
Since DUNS numbers are typically needed when doing business with the U.S. government, it’s a fairly quick method for obtaining a number. You can search for how to do this; you should be taken to the site shown in Figure 3-2, where you can get your number processing started. According to the site’s information, it typically takes about a day to process. However, before Apple will issue a developer license they will need to be able to access that number on the D & B servers. Apple has a close relationship with D & B, and there is even a special Apple contact for handling this type of request. So, while it may seem a little overwhelming at first and you may want to give up, it usually turns out well.
Figure 3-2. Getting a DUNS number is usually quick and easy if you have a legally formed company within your state. However, the number may take a few days to get into the database so Apple can verify your company in order to issue an organizational developer program license
Comments
If you never intend to develop iOS (or Mac OS X) software under your own company, then an individual developer account will certainly be enough to get you started and working almost immediately. On the other hand, if you’re sure you want to develop as a company or work with others on app projects, consider obtaining an organizational developer license from Apple. It costs no more than an individual membership, but you get so much more flexibility. You will need to make sure your business is legally formed and obtain a DUNS number, but that can be completed within a week.
Developer Certificates
Problem
You’ve created an app and you want to start the process of getting it into the App Store for distribution and beta testing.
Solution
You must set up your development computer so that the apps you create are code signed and can thus be trusted to execute on Apple devices before you distribute them to the App Store.
How It Works
Code signing is the process that assures everyone downloading your app that it has not been tampered with and will not introduce viruses or other malware onto their devices. In addition to being code signed, your app must be properly provisioned, which we will talk about in a later section of this chapter.
Your development Mac stores code-signing information in your machine’s keychain, which is the OS X password management system. The certificate process involves identities and other cryptographically related details. It can be incredibly complex to understand if you’ve not previously been involved with operating system security. For our purposes, we only really need to have a basic understanding of how we’ll use these certificates in our endeavors.
The first thing we need to know, if we’re focusing on iOS projects, is that there are two types of certificates: a developer certificate and a distribution certificate . The developer certificates allow our apps to run on devices and access certain app services. Distribution certificates allow you to distribute your apps to designated testing devices and to the App Store .
Without getting into too many details, the signing process begins when installing Xcode, which adds the Apple Worldwide Developer Relations Certifications Authority and Developer ID Certification Authority intermediate certificates to your keychain. Think of these as the starting point of the security chain. From this point you create certificates (developer and distribution) for your team. Each member of your team has their own developer certificate, and as such it will contain their name (Figure 3-3). If you have an individual developer account as opposed to an organization account, your distribution certificate will contain your name. But if developing as an organization, your company’s distribution certificate will contain the name of your business as entered when you set up your program’s credentials (Figure 3-4).
Figure 3-3. With an individual developer account, both your development and distribution certificates will contain your name, since that is how the account was created
Figure 3-4. When using an organization developer account , only one distribution certificate is created
Okay, what I’ve shown you so far in this section is what we’re looking to achieve, but how do we get there? Once we have a valid developer program license from Apple, we head over to the Member Center. As with everything else, the address changes periodically, so you want to search for “Apple developer,” and at the bottom of the page there should be a section for the Member Center. Below that you click on the link for “Certs, IDs and Profiles.”
At this point you might be taken directly to the page where you can create your certificates, IDs, and profiles. You’ll see a taskbar with headers for Certificates, Identifiers, Devices, and Provisioning Profiles. We’ll go through each of these in turn, but first we need to get our certificates in order. If there is a pull-down on the taskbar, make sure it is set to “iOS Apps.” It may be set to “Overview,” “Mac Apps,” or “Safari Extensions,” but we need “iOS Apps.”
Below the Certificates section you’ll see the following choices:
All
Pending
Development
Production
Click on All. It may be already selected, in which case you should see any certificates you already have in the center section of the screen, with a header at the top that should say “iOS Certificates.” Along the top will be a ‘+’ button, which is what we click to create new certificates. Click the ‘+’ button.
As we saw before, there will be a listing of options under the Development and Production choices. We first want to get a development certificate, and once this is completed we’ll perform the same steps for a production certificate . You should see the following options:
Development
iOS App Development
Apple Push Notification SSL (Sandbox)
Production
App Store and Ad Hoc
Apple Push Notification SSL Sandbox and (Production)
Pass Type ID Certificate
Website Push ID Certificate
WatchKit Services Certificate
VoIP Services Certificate
Apple Pay Certificate
Intermediate Certificates
Select the radio button to the left of “iOS App Development,” then click Continue and you’ll be taken to a page that asks you to create a signing certificate . At this point you need to open the Mac Keychain app by locating the icon under Applications that looks like a ring of keys (Figure 3-5). Follow the instructions to create a certificate signing request by selecting Keychain Access ➤ Certificate Assistant ➤ Request a Certificate from a Certificate Authority, as shown in Figure 3-6.
Figure 3-5. Locate and open the Mac Keychain app to create the certificate signing request (CSR)
Figure 3-6. Using Keychain, create a file and save it to your desktop; this will be used to create your development or production/distribution certificate
Fill out the form so that it looks similar to Figure 3-7, but use the email address associated with your iOS account.
Figure 3-7. Fill out the form in Keychain and save the file to your desktop
After saving the file to your desktop—note that you didn’t really take any action on this page other than following the directions to use the Keychain app—click Continue, at which point you will be prompted to upload the file you just created. Click Choose File…, and once the upload has completed—it should be very quick—click Generate. All you need do now is go to the next page and download the certificate. The downloaded certificates will have a .cer suffix like those in Figure 3-8. To complete the process, double-click the downloaded file; Mac OS X will install the certificates in your keychain.
Figure 3-8. The downloaded certificates are self-executing files; double-click the filename to have OS X install them into your keychain
Repeat the preceding steps to create and install a distribution certificate , and we will be all set to continue to the next section. The one thing you will need to do differently is when you’re in the developer portal. As before, click on the ‘+’ button to create a new certificate. In the main window you will see three sections: Development, Production and Intermediate. In the Production section, click the radio button for App Store and Ad Hoc. Follow the reset of the steps exactly as before to install the distribution certificate.
Comments
By following this process, you will have accomplished the first step to being able to install apps for beta testing as well as upload your product to the App Store. To verify that this process was successful, use the Keychain app. On the left under Keychains, select “Login,” and under Category select “My Certificates.” You should see information similar to that shown in Figure 3-4, but for your account information.
Certificate Issues
Problem
For some reason your certificates do not show up properly or have a red X over the icon.
Solution
You most likely are missing the developer intermediate certificate, so you will need to install it from the iOS developer portal.
How It Works
Go back to the page with headers for Certificates, Identifiers, Devices, and Provisioning Profiles. As before, if there is a pull-down on the taskbar, make sure it is set to “iOS Apps.” At the bottom of the page, click on the “World Wide Developer Relations Authority” link to download and install the intermediate certificate as before.
This may or may not correct the issues with your certificates. The first step would be to close everything and reboot your machine if the problem doesn’t get corrected. If you reboot and still see a red X, use Keychain to delete the two certificates you generated, not the developer relations certificate just downloaded, and regenerate your developer and distribution certificates as shown previously.
App IDs
Problem
You’ve created an app or are ready to begin development, but you want to start the process of getting it into the App Store for distribution and beta testing ahead of time.
Solution
Just as we created our development and distribution certificates, we now want to create an app ID within the iOS developer portal for use in identifying our work throughout the process.
How It Works
We will use one of our project names to work through the app ID process. I’m going to use the name of our Objective-C to Swift conversion project. Originally, I called the app Town Slot as a play on the phrase “town slut.” Because you can’t generally reuse app names in the App Store, I’m going to go with Town Slot 2.
Back on the Certificates, Identifiers, Devices, and Profiles page, under Identifiers select “App IDs.” The screen should change to indicate you are registering an app ID. Click on the ‘+’ button to enter the name of the app; I used Town Slot 2 as my name.
Scroll down to the “App ID Suffix” field. This is where you will enter the specific bundle ID of your app, which you will use when creating an app for distribution to beta testers or to the App Store. The normal thing to enter is your company’s reverse DNS domain name followed by the app name. I entered “com.globalteklabs.townslot2.”
If you scroll down a little further you will see a section titled App Services. Some of the items may be selected and grayed out, but we don’t need to add anything else. Later, we may add services to our other projects, but for this conversion project app, all we need are the default settings.
At the bottom click Continue. If you succeed, you will see a screen similar to Figure 3-9 containing your app’s identification information. Beside the Identifier row you will see the app’s bundle ID preceded by a ten-digit alphanumeric sequence, which is the bundle seed ID and essentially represents your company. It’s used in the App Store to identify the apps your company provides, or that you provide as an individual developer, so that any necessary associations can be made with other apps or MFi accessory hardware if applicable. We’ll use this in Xcode later.
Figure 3-9. Double check your app information before submitting; otherwise, you may have to start again with a different app name
After clicking Submit, if everything is entered correctly you’ll see “Registration Complete,” and by clicking Done you should see this app ID in your list of app IDs, as in Figure 3-10.
Figure 3-10. Upon successful registration of your app ID, it should appear in your list of app IDs
Comments
In working through this with the team I assembled to help test out these procedures, the most common issue was using a name that already existed somewhere in the App Store. The app ID in question may not even appear in the store when searching, but most likely someone has used the name previously and the remnants of it have not been removed. More to the point, and from personal experience, I’ve never been able to reuse an app name that I used previously. There appears to be a long-term storage of app names and IDs somewhere within the iOS developer system that does not permit overlapping or duplicate names. It’s similar to not being able to reuse passwords for some lengthy amount of time.
Devices
Problem
You want to test your app on actual iOS hardware.
Solution
In this section we will add our devices to the list of usable devices in the iOS developer system. You are allowed by Apple to add up to one hundred devices throughout the year of your developer program membership.
How It Works
Back on the Certificates, Identifiers, Devices, and Profiles page, under Devices, select “All.” If you have any devices already added, you’ll see them in the center section under iOS Devices. If you see grayed-out names, those are devices that have been disabled and are not usable within the Xcode system.
Before trying to add any new devices, first we need to get information about the devices we want to use. Let’s start with one device, and you can just repeat the process for each additional one you want to add.
Note
As Xcode gets more helpful, processes such as adding devices do become more automated. For example, if you plug in an iPhone on which you wish to install the app you’re working on, Xcode will identify that device as not being in your list and will walk you through adding it. However, I’ve found this works sporadically. The procedures I’m discussing in this section are the primary way that this has been done for years and always works as a fallback, so it’s good to know.
You need to get information about your device, and one easy way to do so is to use iTunes. Start iTunes on your computer, connect your device, and click on the device symbol—iPhone if it’s an iPhone—at the top to see the display shown in Figure 3-11 or something similar.
Figure 3-11. Connect the device you wish to work with using iTunes and go to the device information summary
Make sure you’ve selected the Summary item on the left-hand Settings bar. Left-click on the serial number itself, not the “Serial Number” title, and the display should change to show the UDID as in Figure 3-12.
Figure 3-12. Click on the serial number to change it to display the UDID. Right-click on the UDID number itself and select “Copy” to put the number onto your clipboard
Right-click on the actual UDID number and select “Copy” to put that number into your computer’s clipboard in order to paste it where needed.
Back in the Certificates, Identifiers, Devices, and Profiles section of the developer portal, click the ‘+’ at the top to get to the Registering a New Device or Multiple Devices screen. We’ll work with one device at a time for our practice.
Choose a name for your device, and by that I mean think of something that you wish to call your device as it will appear here, in the developer portal, as well as in Xcode when downloading apps to the device. For the most part, I’d suggest just using the name of your device as shown in iTunes, as you named it during the initial setup. But it doesn’t have to be the same. It’s up to you. Just make sure, especially if you are planning to add multiple devices, that your naming scheme is clear to you. I wouldn’t, for example, name something “Test iPad” or even “Test iPad mini 2,” because you may get another one—if the first one breaks, for example—and then have to deviate from your naming convention. Think it through early on to make it much simpler later on.
Type the name into the “Name” field, paste the UDID into its spot on the Register Device section of the page, and click the Continue button.
Note
At some point, especially if Xcode is open, you may see a message on your device asking if you want to trust this computer. If this is your device and your computer, of course you’ll say yes. A reason you might not want to do so would be if you’re logged into the developer portal on a computer that you don’t intend to use for Xcode development, such as a friend’s Mac.
If the information you entered was valid, you’ll advance to a summary page that tells you how many devices you have left in each category. If the information appears correct, click the Register button, and the device should now appear in the summary pane.
At this point you may want to add any additional devices that you expect to use during development and testing.
Comments
This part of the Xcode setup process is pretty straightforward and generally proceeds without issue. We showed how to add a device that you have with you, but it doesn’t necessarily have to work that way. You could add someone else’s device if they send you their UDID number. I do this often when I create app bundles that I want to distribute to clients who aren’t local. Xcode’s integration with TestFlight has made this less important, and this type of ad hoc distribution has all but been done away with.
Provisioning
Problem
You’ve created an app, and you want to start the process of getting it into the App Store for distribution and beta testing.
Solution
The last of the four primary steps in getting ready to work with actual devices is to create provisioning profiles that a device will use to allow that device to execute app builds generated by Xcode. Profiles are used to make sure that the app is signed and is therefore from a trusted, legitimate source.
How It Works
When you generate a provisioning profile , it includes the three items we previously created: signing certificate, app ID, and device IDs. There are two types of provisioning profiles. Development profiles are used during the build and test process, while distribution profiles are needed when delivering your app to the App Store or for beta testing with users. Profiles can be generated by Xcode or manually by the team agent; that is, the main person in charge of the developer account. Later, we’ll see how to generate certificates using Xcode, but first let’s go through the process of generating a certificate manually.
Back on the Certificates, Identifiers, Devices, and Profiles page, under Provisioning Profiles select “All.” Under the section for generating provisioning profiles manually, there should be a link to create manual profiles . Click on the ‘+’ button to add a new item, and you’ll be taken to the page for generating your profile.
The first step will be to select the type of profile, either development or distribution. Current choices for development include iOS or tvOS. In the distribution category you also get the choice of iOS or tvOS, but for each of those you need to select either App Store or Ad Hoc. The choices on the page should look like this:
Development
iOS App Development
tvOS App Development
Distribution
App Store
Apple TV App Store
Ad Hoc
tvOS Ad Hoc
Let’s walk through creating a development profile for our slot machine game for which we’ve already created an app ID. Select the radio button next to “iOS App Development,” and at the bottom of the page, click Continue.
Note
To create any profile, you’ll use one of your previously created certificates, either developer or distribution, your set of devices, and your app ID. The key is the app ID. You can’t create a provisioning profile until you first set up your app ID in the developer portal.
The next page will ask you to select an app ID via a pull-down that lists the available app IDs. Select the ID for the app of interest. I’m going to select the one for my slot machine game and click on Continue at the bottom of the page.
On the next page you will select the certificate to use for this profile. If the profile will just be used for development, the best option is to select the checkbox next to the development certificate and click the Continue button. Remember that a development certificate will have the names of the different developers on the team, whereas a distribution certificate will show the company name if you set things up as an organization. If you set up your developer account as an individual, then both will show just your name.
The next page will show the list of available devices to which you can attach to this profile. You can click Select All or select individual devices. Selecting all if you only have a small number of devices prevents your having to come back and regenerate the provisioning profile later on. Click Select All and then Continue.
The last page will show you the information so far and provide the opportunity to name your profile. As with other parts of this process, make sure your naming scheme is clear and concise. It also should be easy to identify in a small amount of characters. When we get to Xcode, you’ll see that space is at a premium and being able to identify your profiles early in their name makes things easier to manage. For this profile, I use the name “Dev TownSlot2 ,” as it clearly identifies the app for which the profile is intended and that it is a development certificate. Type the name and click the Generate button.
If everything was correct and valid you should get a page with something that looks like Figure 3-13 displayed. Click on Download to save the provisioning profile to your computer.
Figure 3-13. A successfully generated development provisioning profile is valid for a year from its creation date
Caution
Sometimes you may get a message saying that an “unspecified error occurred.” This often happens when going back and forth between the developer portal page and other web pages in your browser. Simply try generating the profile again, and it should work okay. Otherwise, validate that all the previous steps have been completed and try again. It also might be that one of the items was generated with undetected errors, in which case go back and step-by-step delete the item and regenerate before trying to create a profile.
Once the provisioning profile is on your computer it will be of the form <profile name>.mobileprovision and will look similar to that shown in Figure 3-14. Note that any blanks in your profile name have been converted to underscores.
Figure 3-14. The downloaded provisioning profile looks like this before being installed into Xcode for use in the development process
Comments
So, what do you do with this? The simplest thing is to just drag and drop it on top of the Xcode icon to install it so that Xcode can use it. In the next section, we’ll go into a bit more detail about loading provisioning profiles onto your system so they can be used for app development.
Provisioning Profile Location
Problem
You need to access the actual provisioning profiles installed into Xcode, but you don’t know where they are.
Solution
Set up your Mac to see where the provisioning profiles are located.
How It Works
The provisioning profiles are located in the following directory:
∼/Library/MobileDevice/Provisioning Profiles
The ‘∼’ character represents a shortcut to your home directory . This is the starting point that OS X created for you when you set up your computer. It could be anything, but is typically your user name. For my account, my home directory is MollyDev, as shown in Figure 3-15. The first thing that stands out is that there is no Library subfolder. So what do you do?
Figure 3-15. The author’s home directory shows no Library directory
Throughout the years Apple has endeavored to make their devices more user friendly, but they’ve also tried a number of ways to prevent the novice user from making simple mistakes that can irrevocably damage their file system. One of these is to hide the user’s Library folder. For the vast majority of users this works well. But Xcode developers are, or should be, a bit more savvy, and they occasionally need access to their Library folder. Let’s get OS X to show us our ∼/Library folder.
In a Finder window , select your home directory in the sidebar. If you don’t see your home directory in the sidebar, you need to add that as well. To add your home directory to the sidebar, go to Finder along the topmost menu bar and select “Preferences…,” which should result in the Finder Preferences window popping up. Click on the “Sidebar” option at the top and select the checkbox next to the name of your home folder, as shown in Figure 3-16. You can always navigate to this point using any Finder window, but having your home folder in the Finder’s sidebar makes things so much easier and faster.
Figure 3-16. Use Finder Preferences to show your home directory in the Finder window’s sidebar for easy access during iOS development
Now we can easily select our home folder, but we still won’t see the Library folder. So, as I mentioned previously, select your home folder from the sidebar—in my case this would be MollyDev—and click the gear icon along the top of the Finder window. A list of pull-down options will appear, as in Figure 3-17. Select “Show View Options .”
Figure 3-17. Select “Show View Options” to see what OS X will display in a Finder window
In the View Options window for your home directory, select “Show Library Folder ,” as shown in Figure 3-18.
Figure 3-18. In your home folder’s View Options window, select the checkbox next to “Show Library Folder”
Now, when viewing your home directory you should be able to see your Library folder , as in Figure 3-19.
Figure 3-19. Now you should be able to view the Library folder in your home directory
Navigate to the Provisioning Profiles folder as described earlier, and you should see an empty folder as in Figure 3-20 if you haven’t yet created any profiles or installed this one into Xcode. When you drag the provisioning profile file onto the Xcode icon to install it, you’ll see a profile appear in this folder (Figure 3-21). Note that the name has been changed to a long, seemingly random number used by Xcode, so it will be difficult to determine what profiles are present just by looking at the Provisioning Profiles folder on your Mac. This number is actually a UUID (universally unique identifier), similar to those we’ll discuss later in this book in the section on iOS accessories and Bluetooth.
Figure 3-20. If you’re just getting started and the computer has not yet been used for iOS or other Xcode development, your Provisioning Profiles folder will be empty
Figure 3-21. Once installed, the provisioning profile will appear as a UDID for use by Xcode
When you’re back at writing code and ready to use the profile, Xcode will automatically handle the task of downloading and installing it for you. You may be prompted for your login credentials, but most of the time it just works. Although we haven’t gotten into Xcode yet, I want to show you another way to download provisioning profiles—with the IDE. This saves you from manually downloading profiles from the developer portal and puts the burden of the operation onto Xcode. Sometimes this manual process can be a little flaky. It’s become much more solid over the past year or so, but just in case you run into issues, I want to make sure you have an alternate way to download profiles.
Since you should be familiar somewhat with Xcode, after starting, go to Xcode ➤ Preferences then select “Accounts” if that window is not already open. You’ll see a window like the one shown in Figure 3-22.
Figure 3-22. The Accounts pane of Xcode for the author’s individual and organizational developer accounts
Note
In all of my examples I use the latest beta version of Xcode in order to work with the most current features that are most likely to be present at the time of publishing.
As shown in Figure 3-22, I have two Apple developer accounts. The top one on the left is my individual account, and the other is my organization account. The accounts will initially be identified by the email used to set up your account. The right bottom pane is where you can get information on the details of an account and the available provisioning information. I selected the team name; in this case that’s the organization account, not the individual one, since that’s how we created the profile earlier. Clicking on the View Details… button reveals the information shown in Figure 3-23. Note that we see the same profile that we created in a previous section.
Figure 3-23. Using the Accounts pane of the Xcode organizer, you can create certificates or download provisioning profiles
By clicking Download, you can install any or all profiles within your developer account into Xcode and onto your Mac. Note that you can also generate signing identities for iOS and Mac projects from this pane. There are different options for Mac depending on whether you want to distribute your OS X application directly or through the Mac App Store.
Comments
You’ve seen in this and the previous section details on creating and installing provisioning profiles. These files are the key to your getting your apps to work on devices, distributing them to others for beta testing, and being able to place your work into the App Store . While this discussion was pretty detailed, it is very straightforward and not easy to mess up. I’d advise going through it a couple times until you have it down, then writing yourself a simple step-by-step procedure for the next time. On my Mac I use Stickies and make sure the topmost line is a relevant title. That way, the next time I have to do this and may have forgotten a step, I have the information readily available.
Wildcard App ID
Problem
You want to work on several apps at once but aren’t ready to create a bunch of individual profiles, as they can become difficult to manage in large numbers.
Solution
Create a wildcard app ID that can be used in a provisioning profile across multiple projects.
How It Works
Apple recommends using a wildcard app ID for most iOS development, because this single ID can be used to create multiple applications, including the sample code in the Apple reference library. A wildcard app ID has the form <BUNDLE ID>.*. If your bundle ID were A1B2C3D4E5, then your wildcard app ID would be A1B2C3D4E5.*. Note the difference with something of the form A1B2C3D4E5.com.mycompany.myApp. This is a specific app ID for when you actually want to submit to the App Store or for beta testing. But if you’re only interested in learning and testing on devices, a wildcard app ID works well. So, how do we create one?
Back on the Certificates, Identifiers, Devices, and Profiles page, under Identifiers select “App IDs.” As before, click on ‘+,’ type in the name of the app ID, calling it something like Company Wildcard or whatever is appropriate, then select the proper bundle seed ID in the drop-down. Further down on the page under App ID Prefix, select the “Wildcard App ID” radio button and type in the bundle ID. The bundle ID would be something like com.mollycompany.*, and then you click the Continue button and carry on as before by reviewing the information and clicking Generate on the next page. This will place another app ID into your developer portal information, which you can use to generate a more widely usable provisioning profile.
Note
The bundle seed ID and bundle ID are similar but slightly different. Depending on how it’s used, a bundle ID may or may not include the ten-digit value at the start. It’s used differently throughout the literature. However, the bundle seed ID always refers to that ten-digit value that references your organization or team.
Comments
If you want to practice a lot with installing apps onto devices, especially ones built from Apple demo code, using a wildcard app ID will make life a lot simpler. Not only will you have to do less prep work to get started, but also later on you won’t have as many provisioning profiles that you need to manage and keep track of.
Switching Development Computers
Problem
You want to work on a different Mac but continue developing the same application as you were before. If you try to repeat the preceding steps to create certificates on the new computer, you’ll find that things won’t work anymore. The problem is that you created a signing request on a different computer, so the development and production certificates won’t be the same.
Solution
You need to transfer your development certificate information from your initial development computer to the new computer from within Xcode.
How It Works
This problem always seems to happen at the most inconvenient time. You mostly develop on your large-screen iMac, and for some reason you need to take and show your work to someone else. Perhaps you got stuck and a friend offers to help, or maybe you took my advice in the last chapter and want to give a talk at your local iOS meetup. So you put Xcode onto your laptop, set things up as we talked about, and nothing works; all manner of strange error messages start to appear in the Xcode logs. What happened?
There’s an even worse scenario. You go through the same steps as discussed. You give your talk, and it all works perfectly. At home, getting back into the swing of things, it all stops working. What happened?
What happened was that you generated two different signing certificates (or more)—one for each machine. Recall that before creating and downloading certificates you used the Mac Keychain app to create a certificate request on your machine. That request file has built-in references to that Apple-provided developer certificate as well as information about your machine. So these two requests, created on two different machines (even if they use the same developer account), will be different. As such, both can’t work.
You need to transfer your credentials from one computer to any other computer you wish to use. This is done from within Xcode itself. Let’s work through it. This is another one of those things you should stow away in your quick reference Stickies.
With Xcode in the foreground, select Xcode ➤ Preferences and go to the Accounts pane as we did earlier. At the bottom of the pane (Figure 3-24), click on the gear icon to bring up the export and import options pull-down menu.
Figure 3-24. Click on the gear icon at the bottom of the Accounts pane in the Xcode preferences to bring up export and import options
Selecting “Export Developer Accounts …” brings up the window seen in Figure 3-25, allowing you to name the file for export, provide the location to where it will be saved, and supply a password. Name the file something easy to identify. You can see I named mine myProfileForExport and saved it to my desktop. I usually advise using at least a secure password, but this process doesn’t require anything more than a simple set of numbers. Click Save, and the information will be stored in a single file wherever you’ve requested.
Figure 3-25. Export a single file containing all developer account information from within Xcode. If you’re just moving it from one computer to another in your home, you can go with a simple password. But, because this contains such important account information, you want to make sure it is safe no matter what
Because these credentials contain sensitive information, before writing to a file OS X will verify that you are allowing Xcode to export these credentials to a file from the password Keychain on your Mac. In Figures 3-26 and 3-27 you can see this request after I click on Save. Just click Allow to proceed, and the file should appear at the location you specified after a completion message appears (see Figures 3-28 and 3-29).
Figure 3-26. Xcode requests permission to export your development credentials from Keychain
Figure 3-27. Xcode requests permission to export your distribution credentials from Keychain
Figure 3-28. Upon completion of saving you will be able to see what information was exported
Figure 3-29. Xcode saves the exported information to a single file so that it can be installed on the new development Macintosh computer
Copy the file to a USB drive or move it to the new computer by whatever method works best; place it somewhere that’s easy to find, such as the desktop. If you do use a portable drive, make sure to erase the file from the drive when finished. On the computer to which you moved your credentials and plan to continue development on, start Xcode and go to Xcode ➤ Preferences. Select the Accounts pane at the top as we did earlier during export (Figure 3-24). Select the “Import” option, and you will be prompted for the filename and to enter the password. Once the process completes, Xcode will now operate and build apps using the same credentials as the computer on which you began working.
Comments
The process of moving credentials between computers is certainly one you’ll need to be familiar with when splitting your time between a desktop and laptop. This comes in handy most when you’re operating your own business or as a freelance contractor. When working for a company, either as a direct employee, contract-to-hire position, or 1099 contractor, the IT department will usually set up systems as they see fit. Moving credentials between computers on your own is not permitted except for under special circumstances, such as working from home and using your own equipment.
Summary
As I stated at the beginning, there’s not a lot of witty writing in this chapter. We’ve covered the various situations that you will likely encounter when preparing your Xcode environment to build and run apps on actual Apple devices. Much of the time, Xcode does a lot of the work for you. In fact, if you set up everything on a fresh computer, for example just out of the box with the latest OS X release, just about everything I’ve talked about is automated. But, there’s a problem.
Most of the time iOS developers operate on the edge, so to speak. By that I mean we’ll use the latest beta version of Xcode and iOS frameworks so as to include the latest and greatest new features in our products. We have to, because everyone else, our competition, is doing the same thing. Meanwhile, we may have to support existing production-version apps in the App Store. Beta versions of Xcode and frameworks cannot be submitted to the App Store until just before a GM (Gold Master) release or even later. Typically, I get about a week’s notice before an official Xcode release that I can now submit apps.
This means that we have to run two different versions of everything; that is, two versions of Xcode and two sets of frameworks. Because of that, especially with beta releases, much of the automated processes can be a little unstable at times. We need to know how to do it the hard way, as we’ve described in this chapter, to stay current in our skills. It’s not that we can’t do it the easy way, but we need to make sure it can get done whether it’s the easy way or the more difficult, detailed route that I’ve described.