Book Image

Swift Cookbook

Book Image

Swift Cookbook

Overview of this book

Table of Contents (18 chapters)
Swift Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding a developer account


Usually, Apple tries to make the developer's life easier by improving Xcode and creating tools, but there is an exception when we talk about certificates. If you want to test your app on a physical device (iPhone, iPad, or iPod), you need a certificate. If you would like to upload it onto the App Store, you also need this certificate.

The idea of a certificate is to protect your code from malicious code or from being modified after being signed, but this idea has a price. To get a certificate, you will need to be enrolled on the Apple Developer Program.

Getting ready

I will assume that if you continue with this recipe, you are already enrolled on this program. Let's recycle the previous project; open it, and let's start.

How to do it...

Follow these steps to add an Apple developer account:

  1. Once you've opened the project, click on the project navigator, then click on the combobox that shows our project, and select the target Chapter 1 if it's not selected yet.

  2. Now, have a look at the option called Team. In the case of programming a Mac application, this combobox is enabled only if you select the signing option to Mac App Store or Developer ID.

  3. Usually, the team option starts with None selected. Click over this combobox and select Add Account.

  4. After selecting to add an account, Xcode will ask for your Apple Developer Program login data (e-mail and password). If you don't have it, you have the option to join the program.

  5. Once you've added this, you are supposed to use your account and run your app. If you have a device attached to your Mac, you can go to the Window option on the menu bar, and then you can select the Devices option.

    Your device should appear on the dialog, Xcode could take a while to read the device's symbols. In case of having this device attached for the first time, you will see that you will have to ask to change the status of this device to developer mode.

  6. When you get the green light, it means that your device is ready to be used for development; now, go back to your project and change from the simulator to your device.

    If the device is enabled, but not listed by Xcode, it could mean that you have to decrease the iOS Deployment Target, which can be found on the project setting, under the Info tab.

Tip

Lowering the iOS Deployment Target to the minimum value is an idea very common among programmers to cover the maximum sort of devices. Doing this will prevent your development from using new features. Check out the features that you need first, and then change your iOS Deployment Target.

How it works...

Signing a code is something done for security; the main restriction is that you must be up to date with the Apple Developer Program. Apple allows having up to 100 devices per account.

There's more...

Sometimes, the certificate gives us some headache; take care if it asks you to revoke your certificate; you may have to create a new one on the Apple Developer Center, and if you are working on a team, you may have to wait for the administrator's approval.

There are a few times that you need to change the code signing option on the build settings; it happens mainly when you get code from another organization ID.

Testing your code on a device is something that is very useful; it's where you can test the real user experience. Whenever you have some low-level code, such as assembly code or something written in C language that uses type sizes or byte orders, it's good to test your project on a device. Remember that Apple's devices have CPUs based on ARM and ARM64, which are different to the Intel CPU that is used on Mac computers.