Friday, January 22, 2016

Deploy your app on an iPhone/iPad (Developer Profile)

Requirements:
– You’re going to need to enroll in the
 Apple iOS developer program which is $99 a year.
– You’ll also need an actual iOS device.
Request your certificates
Your certificate is used to code sign the apps and they uniquely identify you. In this step, we have to generate and request two certificates: one for development and one for distribution. We only need to do this once (not for each app!).
The development one is used for testing while the distribution certificate is used to sign your app bundle for distribution in the App Store once it’s ready.
Now that you’re enrolled in the Apple developer program, you can launch Xcode 5 and go to your preferences menu. Then go to the “Accounts” tab.
Fill in your Apple iOS developer account details here.
Once you’re signed in, click “View Details…” and you’ll get to this panel where you can see your existing certificates and provisioning profiles.
If you click the “+” icon below the certificates pane, you can request a new iOS Development Certificate. Go ahead and do that now.
Also do the same thing and request an
 iOS Distribution Certificate as well.
Afterwards, if you login to your your iOS provisioning portal and go to “Certificates”, you can see that it’s actually been created!
In the past, this used to be a lot more tedious and you’d have to go through multiple steps to generate the request on your computer and then upload it to Apple through the provisioning portal. It’s nice that it’s integrated into Xcode 5 now!
Before we can install the app on our device for testing, we’ll need to do a few things:
1. Configure the device for development and add the device to the member center
2. Create a provisioning profile for your app
3. Make sure your app is set to use that provisioning profile
4. Finally deploy the app to the device
This may seem really tedious (and it kinda is), but the reason for it is that the Xcode provisioning profile defines several key pieces of info such as what devices are allowed to install your app, an App ID to identify it with what’s registered in the portal and the development certificates.
The profile gets installed onto the device and then you’ll be able to deploy your iOS app to it.
Once we go through it, you’ll understand that it’s quite straight forward!
1. Configure the device for development and add the device to the member center
All we need to do here is plug in the iPhone or iPad to your computer with the USB cable.
This will usually launch iTunes and the thing to watch out for is that if your device is new, iTunes will ask you to set it up as a new device or restore a backup.
You have to get past this step or else it interferes with what we’re going to do in Xcode 5 to configure the device.
So make sure that your device is ready by seeing a screen like this in iTunes:
If your iTunes window is asking you to set up the phone, you want to do it!
Next, you want to go back to Xcode 5 and go into your Organizer window by either pressing SHIFT+CMD+2 or using the menu option here:
Click the Devices tab at the top of the Xcode Organizer window. Then along the left hand side, you’ll see the device that you have connected (along with all the previous devices you’ve connected before).
Choose the currently connected device from the list.
You’ll see a screen like this and you want to click the Use For Development button. After it finishes configuring the device for development, click the Add To Member Center button. If you don’t see a Use For Development button, then it means that this device has been used for development before and you just need to add it to the member center.
When you click the Add To Member Center button, it’ll ask you to choose an account. The one that you added earlier should show up. Select that one and click “Choose”.
2. Create a provisioning profile for your app
Next, login to your iOS Provisioning Portal; it’s time to create the App ID and iOS provisioning profile for your app!
Remember when you set up a new Xcode 5 project and you had to fill in a product name and a company identifier and both of those came together to form your bundle identifier? Well that comes into play now!


In your provisioning portal, go to the App IDs section.



Give your app a name and then scroll down a little to the explicit app id section and put in the same bundle identifier that you had set up for your Xcode project.
Then click “continue” and on the following confirmation screen, click “submit”.
Now go to the development provisioning profiles section. We’re going to create a new development iOS provisioning profile for the new App ID we just added.
Choose iOS App Development for the type and click “continue”.



On the next screen, choose the App ID that you just added in the drop down.
On the next screen, select the development certificate and click “continue”.
Now, finally you can select the devices that your app is allowed to be installed on so select the one that you added earlier through the Xcode 5 Organizer.
On the final screen, you can give the provisioning profile a name and generate it.

Click the blue Download button and the profile will be downloaded onto your computer. Go to the location where you saved it and then double-click the provisioning profile.
You may notice that there’s a provisioning profile expiration date. When the time comes, you can renew provisioning profile by going to where your profiles are listed and click “renew” beside the one that’s going to expire.
3. Make sure your app is set to use that Xcode provisioning profile
We’re almost ready to deploy the app onto our iOS device! The last step is to make sure that our app is set to use this new profile.
It’s crucial that your Xcode project bundle ID matches the bundle ID that you specified when you created your App ID or else you won’t be able to use this provisioning profile for this app.
Go to your Xcode 5 organizer and check that the profile is installed on your device by going to the “provisioning profile” section under your device in the Organizer.
(This can also be a great way to resolve “provisioning profile can’t be found” error messages)

Next click on the root project node in your Xcode file navigator and on the right pane you’ll see the settings for your project.
Click the Build Settings tab and scroll down to the Code Signing part.
You want to make sure that the code signing identity is set to use the certificate you created in the first step.
If you’re doing testing and development, you’ll want to select “iOS Developer” and if you’re signing to distribute your app to the App Store, you’ll want to choose “iOS Distribution”.
Both of these settings are automatic settings, meaning they’ll automatically select the signing identity to use. If you’ve only got one development and one distribution signing identity (which is most likely since you just requested one of each in step 1), then this automatic setting is ok, but if you have multiple signing identities then it may be best to explicitly select the signing identity that you want to use.

While you’re in the build settings, one thing to keep in mind is that when you create an Xcode 5 project, it defaults to a minimum deployment target of iOS 7.
That means that the device that you deploy the app on must be at least running iOS 7.0.
Settings if you want to include iOS 6 for deployment
In this example, I connected my iOS 6 device so I need to change my project settings to have a minimum deployment target of 6.0.
The architecture setting needs to be changed as well if you set your deployment target to 6.0. (note: you only need to do this if you set your deployment target to 6.0)


4. Finally deploy the app to the device
Now if everything is set up correctly, you’ll see the name of your phone in the list of deployable targets.
If you only see “iOS Device”, it won’t work. You’ll need to actually see the name of your device in the list.
So select your device and run the project to deploy the app on your phone!

Troubleshooting
Don’t see your device name on the list of deployment targets?
It can be really frustrating because there are so many steps in different places.My advice would be to retrace your steps and make sure that you didn’t miss anything.The first thing to try is to disconnect your device and then reconnect it. Then check the following steps.
1. You don’t need to request new certificates if you can see them in your provisioning portal.
2. Plug in your device and re-add it to the member center through the Xcode 5 organizer.
3. In the portal, double check that the App ID you created matches the one in your project.
4. In the portal, double check that the
 provisioning profile includes the device you have connected.
5. Re-download it and double-click it.
6. Go into your Xcode Organizer and under the connected device, in the provisioning profiles section, make sure you see the profile.
7. In your project build settings, make sure that your code signing settings are using the proper signing identities.
8. In your project build settings, make sure the deployment target is lower than the iOS version that your connected device is running.
9. Go to iTunes and make sure it’s not asking you to set up a new phone or restore a back up (this can interfere).



Share:

0 comments:

Post a Comment