Monday 26 November 2012

How to TEST an Application on a REAL Device

youtube link  --http://www.youtube.com/watch?v=lPwlhKgZHCM


OR


Provisioning is the way by which you can test on a device. Only iPhone developer program members get this privilege - which is reasonably priced at $99/year. All of the action starts at the Developer program portal.
Here's what you need to do for on-device testing:
  • Create a certificate
  • Create a specific or Wild-card App ID
  • Add one or more test devices
  • Create a provisioning profile
  • Install the app on the test device(s)
  • Go have a beer if it all worked!

Certificates

You'll probably need at least one development certificate and one distribution certificate. You'll need a development certificate if you want to test with the APNS (Apple Push Notification Service) sandbox, or if you want to debug on the device with Xcode. I've never needed more than one of each. The distribution certificate can be used for both Ad Hoc and App Store distributions. Each certificate can be mapped to one or more devices in a profile when provisioning.
Creating a new certificate:
  • Enter the program portal
  • Click on the "Certificates" link on the left panel
  • Select the "Development" or "Distribution" tab
  • Follow the steps under the "How To" tab to actually create a certificate:
    • Generating a Certificate Signing Request
    • Submitting a Certificate Signing Request for Approval
    • Approving Certificate Signing Requests
    • Downloading and Installing Development Certificates
    • Saving your Private Key and Transferring to other Systems
Note: make sure that you install the "WWDR Intermediate Certificate".

App IDs

Apple says: "App IDs are an integral part of the iPhone Development and Provisioning Process that allows an application to communicate with the Apple Push Notification service and/or an external hardware accessory." For every app that uses APNS, In App Purchase, or external hardware accessories, you will need a specific App ID. All other apps can use a Wild-card App ID.
Example App IDs:
  5LL056TAKK.com.foo.bar (specific)
  78AGBPA5X8.* (Wild-Card)
The 10 characters at the start of the ID is called the "Bundle Seed ID". For specific App IDs, the remainder (ex: com.foo.bar) must match the Bundle Identifier (CFBundleID) in the application's info.plist file. I recommend using a single Wild-card App ID for all of your applications that are not using APNS, In App Purchase, or external hardware accessories. You do notever need to enter the Bundle Seed ID into Xcode.
Creating a new App ID:
  • Enter the program portal
  • Click on the "App IDs" link on the left panel
  • Follow the steps under the "How To" tab to actually create an App ID:
    • Generating an App ID
    • Registering an App ID for Apple Push Notification service
    • Registering an App ID for In App Purchases

Devices

This is how you add a new device (iPhone, iPod Touch and maybe even the new iPad) to your account. Such devices can then be provisioned with a development or distribution profile to run apps that are not available in the App Store (this is called "Ad Hoc" distribution).
Adding new devices:
  • Enter the program portal
  • Click on the "Devices" link on the left panel
  • Click on "Add Devices" to enter each device's ID (40 hex characters). The device ID is available from iBeta (a free download from the app store) or from iTunes by clicking on the "Serial Number" label in the device's "Summary" tab. See here for more info.
Note: You can only have 100 devices per license-year. If you delete a device, the slot won't actually be available until the renewal date of your license. Once you add a device after your renewal date, all used slots get locked-in until the NEXT year.

Provisioning

You will probably create at least 3 provisioning profiles: one for development, one for Ad Hoc distribution, and the third for App Store distribution. Each profile must map to one App ID, one or more certificates, and one or more devices. I've never needed to specify more than one certificate in a profile.
Creating a profile:
  • Enter the program portal
  • Click on the "Provisioning" link on the left panel
  • Select the "Development" or "Distribution" tab
  • Click on "New Profile"
  • Pick a new profile name, certificate, App ID, and devices. If there are no devices in the list, you can always edit the profile later.
  • Click "Submit". If the status beside the new profile says "Pending", just wait a few seconds, then refresh the page.
  • Click "Download" and save the file to somewhere on your machine. It'll have a funny extension called .mobileprovision. For Ad Hoc distribution, you will need to email this file to anyone that gives you their device ID. Some email programs (Outlook Web Access comes to mind) will treat this file as a virus, so you might need to package it in a ZIP file.

On-device testing - finally!

Now that you have a provisioning profile, what do you do with it? For Ad Hoc testers, you'll email them that file, which they will drag into iTunes before installing the application binary as described here. But first, you'll need to modify your Xcode project (if you haven't already) to use the profile.
  • Install the new profile into Xcode. You do this by dragging the file onto the Xcode icon in the application dock. It should create a file in~/Library/MobileDevice/Provisioning Profiles.
  • In Xcode, you need to decide which build configuraion(s) you want to use for device testing (for both Ad Hoc and App Store distributions). When you create a new project, you get "Debug" and "Release" configurations. I usually create two new configurations, "Distribution" and "App Store", for Ad Hoc and App Store distributions respectively. I reuse the Debug configuration for on-device Development testing. This gives me the following build combinations:
    • Simulator | Debug
    • Simulator | Release
    • Device | Debug
    • Device | Distribution
    • Device | App Store
  • In Xcode, add the new profile to the desired configuration(s) using Project | Edit Project Settings | Build tab | Code Signing category. The gory details of how to create new build configurations and assign profiles to them can be found here:
    • Enter the program portal
    • Click on the "Distribution" link on the left panel
    • Under the "Prepare App" tab, read the "Building your Application with Xcode for Distribution" instructions
  • Clean all targets and build! With any luck, you'll end up with a .app "file" (it's actually a directory, but looks like a file) in the build directory. You can easily find this directory by expanding the Products folder in Xcode's left pane, right-clicking on the .app "file" and selecting "Reveal in Finder".
For Ad Hoc distribution:
  • Right click on the .app "file" and select Compress to create a ZIP file - recipients must unzip that file before dragging the extracted .app "file" into iTunes after they have installed the provisioning profile that contains their device
For local device testing:
  • Connect the iPhone to your Mac using the standard USB cable
  • Do "Build and Run" to compile the project and install it on your device. This works for both Development and Distribution profiles. Newer versions of Xcode are smart enough to prompt you to install the right profile on the device if it's missing.
  • If you keep the phone connected while you run your app, you can view the console output using the Xcode Organizer (Window | Organizer)

Tips

Here are some random tips that might make your life easier. Maybe.
  • If you add new devices to an existing provisioning profile, you do not need to rebuild the binary with the new profile. You can simply send the new profile to the new devices' owners and they can use any previously-built binary that was paired with an older version of that profile.
  • Coming soon - creating IPA files
  • Coming soon - deciphering pesky iTunes/Xcode error messages
  • Coming soon - what's get-task-allow all about?

No comments:

Post a Comment