Configuring iOS development environment

Creating iOS development environment is a straightforward process if you meet the requirements. In order to have an iOS development environment, you need to:

  • Have a Mac machine that runs OS X Mountain Lion (10.8) or higher versions
  • Install Xcode on your Mac machine
  • Install the iOS SDK on your Mac machine

Xcode is the official Apple IDE that allows you to develop applications for Mac, iPhone, and iPad. Xcode has a lot of great features, some of which are:

  • Source code editor
  • Assistant editor
  • User-interface builder
  • iOS simulator
  • Static code analyzer
  • A powerful built-in open source low-level virtual machine (LLVM) compiler for C, C++, and Objective-C
  • The Live Issues feature, which highlights the common coding mistakes while coding your application, without the need to build your project
  • Complete support for SCM systems (subversion and Git source control)

You can download the latest version of Xcode from the Apple App Store on your Mac machine. You will find the iOS SDK included with Xcode, so there is no need to download anything other than Xcode.

In order to download the latest version of Xcode, follow these steps:

  1. Open the App Store application on your Mac machine.
  2. In the search field of App Store, type in Xcode and press enter.
  3. Download Xcode, and after completing the download, you will find it under your applications directory. The following screenshot shows the Xcode icon:
    Configuring iOS development environment

    The Xcode icon

If you have an earlier version of OS X (less than 10.8), you need to upgrade it. In order to download Xcode, you need OS X Version 10.8 (or higher).

Importing the Sound Recorder application into Xcode

Now, it is time to make our Sound Recorder application support iPad and iPhone devices. The following command adds iOS platform support for our Sound Recorder application:

> cordova platform add ios

Then, build our application in the iOS platform using the following Cordova build command:

> cordova build ios

Open your Xcode environment, click on Open other, and then select the SoundRecorder.xcodeproj file under the platforms/ios directory to open our Sound Recorder iOS project.

You will find our Sound Recorder application open in Xcode. In order to run our project on an iPhone (or iPad) emulator, click on the Build and run button after selecting the iPhone emulator, as shown in the following screenshot:

Importing the Sound Recorder application into Xcode

Running the Sound Recorder application in Xcode

After clicking on the Build and run button, the iPhone emulator will be launched with our Sound Recorder application and you can start using it.

An important point that you have to be aware of is that if you are deploying your application on iOS 7, and because of a bug in Apache Cordova 3.4, you will find an overlay between your application and the device status bar, as shown in the following screenshot:

Importing the Sound Recorder application into Xcode

Apache Cordova 3.4 bug with iOS 7

In order to fix this issue (which I hope to be fixed soon in the next releases of Apache Cordova 3.x), one of the possible workarounds is to hide the status bar by adding and setting two properties in our SoundRecorder-info.plist file, which is located under the Resources directory of our application, as shown in the following screenshot:

Importing the Sound Recorder application into Xcode

Adding properties to the SoundRecorder-info.plist file

The two properties and values are:

  • The Status bar is initially hidden property set to the YES value
  • The View controller-based status bar appearance property set to the NO value

    Tip

    In order to add a property to the *-info.plist file, you can select the information list property in Xcode and then click on Add Row.

After setting these two properties, click on the Build and run button again to see the fixed screen in iOS 7, as shown in the following screenshot:

Importing the Sound Recorder application into Xcode

The Sound Recorder application fixed in iOS 7

Running the Sound Recorder application on a real iOS device

In order to deploy our Sound Recorder application on a real iOS device (iPhone or iPad), you will need to follow these 20 steps carefully:

  1. Sign up for the iOS developer program at https://developer.apple.com/programs/ios/. There are two available enrollment types:
    • Individual: Select this enrollment type if you are an individual
    • Company/Organization: Select this enrollment type if you represent a company

      Tip

      Sign up to the Individual program if you just want to develop applications in App Store. Note that at the time of writing this book, this will cost you 99 USD per year.

  2. Generate a Certificate Signing Request (CSR) using the Keychain Access application, which you can get from the /Applications/Utilities directory. In order to generate the certificate signing request, follow these steps:
    1. Navigate to Keychain Access | Certificate Assistant | Request a Certificate From a Certificate Authority, as shown in the following screenshot:
      Running the Sound Recorder application on a real iOS device

      Creating a CSR using Keychain Access

    2. In the Certificate Assistant window, enter your e-mail address, click on the Saved to disk radio button, and check the Let me specify key pair information checkbox. Then, click on Continue.
    3. In the Key Pair Information window, choose 2048 bits as the key size and RSA as the algorithm. Then, click on Continue.
    4. Use the default filename to save the certificate request to your disk, and click on Save.

      Tip

      By default, the generated certificate request file has the filename with the following extension CertificateSigningRequest.certSigningRequest.

  3. Now, we need to use the iOS member center (https://developer.apple.com/membercenter/) in order to create the application ID, register your iOS device, generate a development certificate, and create a provision profile.
  4. Click on the Certificates, Identifiers & Profiles link, as shown in the following screenshot. You will be introduced to the overview page, where you can click on the Identifiers link.
    Running the Sound Recorder application on a real iOS device

    Managing certificates, identifiers, and profiles from the member center

  5. Select App IDs from Identifiers. Register your application ID by entering an application name and the application bundle identifier (you can get the bundle identifier from the SoundRecorder-info.plist file), as shown in the following screenshot. Then, click on Continue.
    Running the Sound Recorder application on a real iOS device

    Registering your application ID

  6. You will be introduced to the confirmation page. Click on Submit to confirm your application ID.
  7. Select All from Devices. Register your iOS device by entering the device name and the device's Unique Identifier (UDID), as shown in the following screenshot. Then, click on Continue.

    Running the Sound Recorder application on a real iOS device

    Registering your iOS device

    Tip

    In order to get your iOS device's UDID, you can get it after connecting your iOS device to iTunes. Select your device from the left-hand side menu of iTunes and then click on Serial Number; you will find it changed to Identifier (UDID) with the device UDID.

  8. You will be introduced to the review page. Click on Register to register your device.
  9. Select Development in Certificates to create your development certificate file. Read the introduction page and click on Continue.
  10. In the second step of the development certificate creation process, choose the CSR file that we created in step 2 and click on the Generate button, as shown in the following screenshot:
    Running the Sound Recorder application on a real iOS device

    Generating your development certificate

  11. In the last step of the development certificate creation process, click on the Download button to download the development certificate to your machine.
  12. Select All from the Provision Profiles to create a provision profile, which will be installed on your iOS device. Choose the iOS App Development option from Development, as shown in the following screenshot, and then click on Continue:
    Running the Sound Recorder application on a real iOS device

    Selecting the iOS App Development provisioning profile

  13. In the second step of the development provisioning profile creation process, select App ID, which we created in step 5, and then click on the Continue button.
  14. In step 3 of the development provisioning profile creation process, select the Development certificate checkbox that we created in step 10, as shown in the following screenshot, and then click on the Continue button:
    Running the Sound Recorder application on a real iOS device

    Selecting the certificate to include in the provisioning profile

  15. In step 4 of the development provisioning profile creation process, select your iOS device checkbox, which you registered in step 8, and then click on the Continue button.
  16. In step 5 of the development provisioning profile creation process, enter your preferred profile name (for example, SoundRecorderProfile) and then click on the Generate button.
  17. In the last step of the development provisioning profile creation process, click on the Download button to download the provisioning profile to your machine.
  18. Now that we have created and downloaded both the development certificate and the provisioning profile, we need to install them. Double-click on the .cer file that you downloaded in step 11 to install it onto a keychain on your Mac machine. If you are prompted with the Add Certificates dialog, click on OK.
  19. In order to install the downloaded provisioning profile to your iOS device, connect your iOS device to your Mac, open the organizer application from your Xcode by selecting Organizer from Window menu, and then click on the Add button and select the .mobileprovision file. You should find that this profile is a valid one, as shown in the following screenshot:
    Running the Sound Recorder application on a real iOS device

    Adding a mobile provisioning profile to an iOS device

  20. Finally, you can deploy your application on your iOS device by selecting your iOS device from the active scheme dropdown and clicking on the Build and run button, as shown in the following screenshot. After clicking on the button, you will find our Sound Recorder application finally launched on your iOS device.
    Running the Sound Recorder application on a real iOS device

    Deploying our Sound Recorder application to a real iOS device

When running your iOS application on a real device for the first time, you will receive the prompt message codesign wants to sign using key "-----" in your keychain. If you see this message, click on the Always allow button.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.31.125