Xamarin.Basics – Ad Hoc iOS Builds, Part 1: Certificates and Profiles

For those who are newer to iOS application development and are trying to run their app on devices or deploy it to others’ devices, let me first offer you my condolences. Now let’s look at the overwhelming number of steps required to do a basic build on an iOS device!

Resources Required Before Starting

  1. A Mac. You can’t do this without an actual Mac device running OSX
  2. XCode installed on the Mac
  3. An Apple Developer license (read below)

Join the Apple Developer Program

In order to distribute apps, you’ll need to create certificates and profiles in the end. Before you can do that, you’ll need to join the Apple developer program for iOS. Keep in mind, this can take time (multiple days).

Head over to https://developer.apple.com/programs/ and click on the Enroll button.

apple_enroll

You’ll see an intimidating following something like this:

Enrolling as an Individual

If you are an individual or sole proprietor/single person business, sign in with your Apple ID to get started. You’ll need to provide basic personal information, including your legal name and address.

Enrolling as an Organization

If you’re enrolling your organization, you’ll need an Apple ID as well as the following to get started:

 
A D-U-N-S® Number

Your organization must have a D-U-N-S Number so that we can verify your organization’s identity and legal entity status. These unique nine-digit numbers are assigned by Dun & Bradstreet and are widely used as standard business identifiers. You can check to see if your organization already has a D-U-N-S Number and request one if necessary. They are free in most jurisdictions. Learn more

 
Legal Entity Status

Your organization must be a legal entity so that it can enter into contracts with Apple. We do not accept DBAs, fictitious businesses, trade names, or branches.

Legal Binding Authority

As the person enrolling your organization in the Apple Developer Program, you must have the legal authority to bind your organization to legal agreements. You must be the organization’s owner/founder, executive team member, senior project lead, or have legal authority granted to you by a senior employee.

Follow all the steps for either an individual or organization. PS. This costs about $100 (as of June 2017). Once you’ve submitted your enrollment application, an Apple employee will review your request and get back to you within 1-2 business days (usually) with your accepted (or declined) enrollment. Once this is done, you’ll be able to access the developer portal where you can add other members of your organization, manage certificates, apps, devices, and profiles.

Getting the Proper Requirements for Ad Hoc

Now that you can access the portal, go to the Developer portal and click on Account to sign in with your Apple ID.

After signing in, you’ll see some options on the left navigation bar. Click on Certificates, IDs, and Profiles

Components You Will Get From This Post

There are 4 major components you will need in order to be able to deploy an app to multiple devices:

  1. An App ID
  2. An Ad Hoc Certificate – created, downloaded, and installed on the machine.
  3. The UDIDs of every iOS device that will run the app
  4. A Provisioning Profile that combines all three things

Creating an App ID

In the developer portal Certificates, IDs, and Profiles section, click on App IDs from the left menu, then click the plus button in the top right:
Screen Shot 2017-06-21 at 10.33.47 AMScreen Shot 2017-06-21 at 10.23.59 AMScreen Shot 2017-06-21 at 10.24.04 AM

Then fill out the fields for Name and Bundle Identifier.
Screen Shot 2017-06-21 at 10.24.22 AMScreen Shot 2017-06-21 at 10.24.36 AM

Scroll on down and select the additional App Services this app will need to support:Screen Shot 2017-06-21 at 10.24.50 AM

Click Continue and you’ll be done creating your App ID and can continue to creating a certificate.

Creating a Distribution Certificate

Over in the left navigation, click on Certificates > Production then click the plus button in the top right:Screen Shot 2017-06-21 at 10.25.06 AMScreen Shot 2017-06-21 at 10.25.10 AM

In the Production select App Store and Ad Hoc, then scroll down to Continue:

Screen Shot 2017-06-21 at 10.25.20 AM

You’ll then see a page that explains how to create a Certificate Signing Request that is required to generate the Certificate. Click Continue, then in the Mac open the Keychain Access application.
Then from the Keychain Access menu, go to Certificate Assistant and Request a Certificate from a Certificate Authority:
cert_request

Fill out the form and save the request file locally:
Screen Shot 2017-06-21 at 10.26.09 AM

Take this newly saved file and go back to the Apple Developer Portal and upload it:

upload_cert

Click Continue and you’ll now be able to download the Certificate. Double click / open the newly downloaded certificate, and it will be installed into your keychain.

Important Notes About Certificates

Guess what! It gets more complicated and annoying!

Once you’ve created a certificate, you can ONLY USE IT on the machine that created the signing request due to the signing mechanism. In order to allow a user to use the certificate, you’ll need to export it to a .p12 file which is then signed by a new password. The other Mac user can then take that .p12 file and save it to their keychain using said password. We won’t go into depth about this process in this post, but perhaps in a follow-up.

Adding iOS Devices

In order to install an ad-hoc or non-App Store iOS app, the devices that will install and run the app need to be registered and eventually included in part of the build process. In the Apple Developer Portal we can add devices to our profile (up to 100 devices).

In the left navigation, click on Devices > All then once again click the plus button in the top right:Screen Shot 2017-06-21 at 10.26.56 AM

Give your new device a Name and then get the UDID of the device.

Getting the UDID of an iOS Device

Plug in your iOS device to your Mac and open iTunes if it doesn’t open automatically. In iTunes, click on the device button to get to the device details:Screen Shot 2017-06-21 at 11.50.49 AM.png

You’ll notice that there is no UDID field! Here’s the secret: click the device’s Serial Number to reveal the UDID:

Copy the UDID.

Back in the Apple Developer Portal add the UDID and click Continue to save the device.

Now that we have an App ID, Certificate, and our devices, the last step is to create a Provisioning Profile and install it on the Mac.

Creating an Ad Hoc Provisioning Profile

In the left navigation, click on Provisioning Profiles > Distribution and then the plus button in the top right.Screen Shot 2017-06-21 at 10.33.16 AM

Next you’ll be asked which type of Profile you want to create. Select Ad Hoc under the Distribution section.Screen Shot 2017-06-21 at 10.33.22 AM

Click Continue and you’ll then need to select which App ID this profile is for. In the dropdown, select the App ID you created:select_app_id

Click Continue and you’ll need to select the Distribution Certificate to associate with the profile. Select the certificate you just created:
Screen Shot 2017-06-21 at 10.33.50 AM

Click Continue and you’ll need to select the devices that are allowed to run this application built with this profile. Select the devices you added or want to enable:Screen Shot 2017-06-21 at 10.34.00 AM

Click Continue and give your profile a Nameprofile_preview
Click Continue and you can review the profile before generating it.

Click Generate and then Download the profile. Double-Click or open the newly downloaded profile and it will then be instlled into XCode.

Now with your certificate installed on the machine’s keychain and the profile installed into XCode, you’ll be able to build against iOS devices in Release. Doing this build will then generate an .ipa file. This file is what can be uploaded to Mobile Center, HockeyApp, or any other distribution channel you want to use.

Next Steps

In the next few blog posts, we’ll look at actually uploading a new build .ipa file to both HockeyApp and Mobile Center so that test users can download and install it on their devices. Stay tuned!

If you like what you see, don’t forget to follow me on twitter @Suave_Pirate, check out my GitHub, and subscribe to my blog to learn more mobile developer tips and tricks!

Interested in sponsoring developer content? Message @Suave_Pirate on twitter for details.

One thought on “Xamarin.Basics – Ad Hoc iOS Builds, Part 1: Certificates and Profiles”

Leave a comment