Running the app on your device

Source: Internet
Author: User

Running the app on your device

So far, you 've run the app on the Simulator. That's nice and all but probably notwhy you're learning iOS development. You want to make apps that run on realiPhones! There's hardly a thing more exciting than running an app thatYouMadeon your own phone.

Don't get me wrong: developing your apps on the Simulator works very well. Whendeveloping, I spend most of my time with the Simulator and only test the app onmy iPhone every so often.

The Simulator is great, but you do need to run your creations on a real device inorder to test them properly.

And, of course, to show the fruits of your labor to other people!

Get with the program

You cannot run apps on your iPhone unless you have a paid iOS starter program account. Without this account, your apps will never leave theSimulator.

While it is possible to do a lot of development work on the Simulator, somethings it simply cannot do. if your app needs the iPhone's accelerometer, forexample, you have no choice but to test that functionality on an actual device. don't sit there and shake your Mac!

You also need to be a member of the paid Developer Program if you want toput your apps on the iTunes App Store.

Go todeveloper.apple.com/programs/iosto sign up.

In order to allow Xcode to put an app on your iPhone, the app must beDigitallysignedWith yourDevelopment Certificate. Apps that you want to submit to theApp Store must be signed with another certificate, theDistribution Certificate.

ACertificateIs an electronic document that identifies you as an iOS applicationdeveloper and is valid only for a limited amount of time. These certificates are partof your Developer Program account.

In addition to a valid certificate, you also need a so-calledProvisioning Profileforeach app you make. xcode uses this profile to sign the app for use on your device. the specifics don't really matter, just know that you need a provisioning profile orthe app won't go on your device.

Any devices you want to use with Xcode on must be registered with your program account. there is a limit to how to configure devices you can register, currentlyup to 100. this may sound like plenty-you probably don't have a hundred iPhoneslying around-but this includes des devices of beta testers and anyone else you want todistribute your app to outside of the App Store. use them sparingly!

(Note: New in iOS 8 is support for the TestFlight beta testing service, which doesnot require you to register the devices of beta testers with your account .)

Making the certificates and provisioning profiles used to be frustrating and error-prone. Fortunately, those days are over: Xcode 6 makes it really easy.

! Connect your iPhone, iPod touch, or iPad to your Mac using the USB cable.
! From the Xcode menu bar selectWindow → Devicesto open Xcode's Devices

Window.
Mine looks like this (I'm using an iPad mini ):




<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + Environment + PGJyPgo8L3A + Environment + cda-vcd4kpha + PGJyPgo8L3A + Environment + PGJyPgo8L3A + Environment cjxwPjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20141026/2014102609490384.png" align = "left" alt = "\">













! Click the + button at the bottom and chooseAdd Apple ID. Xcode will ask for your Apple ID:





! Type the username and password for your Developer Program. This is the samelogin that you use for the iOS Dev Center website.

Xcode verifies your account details and adds them to the accounts window .! Click theView Details... button in the bottom-right corner.

This brings up another panel, listing your signing identities (the certificates) and theprovisioning profiles. Currently this panel will be empty:




! Click the arrow in the bottom-left corner. Xcode now contacts the iOS Dev Center

To fetch any certificates and provisioning profiles that you already have.

If this is your first time, you'll get the following message because you do not have aDevelopment Certificate yet:




! ClickRequestand wait a few seconds. Great! That wasn't so hard, was it ?!

While you're waiting, Xcode automatically registers your device with your program account, creates a new Development Certificate, and downloads andinstils the so-called Team Provisioning Profile on your device. (They call it the "team" profile because it will work on all the devices that you have registered withthe Developer Program .)

When you're done, close the Accounts window and return to the Devices window. You can see the profiles that are installed on your device by right-clicking

Device name and choosingShow Provisioning Profiles:



The Team Provisioning Profile has a so-calledWildcard App ID(*), Which means youcan use it for any application you are developing (as long as they don't require anyspecial features such as push notifications ).

Thanks to the Team Provisioning Profile you won't have to repeat this procedure forany of the other apps that you will be developing in this series. xcode knows aboutthe profile now and it will automatically use this profile to sign your apps.


You can also login to the iOS Dev Center website to see what the provisioningprofile looks like there. Needless to say, you only have access to this portal if you 'rein the paid iOS Developer Program.

! Go todeveloper.apple.com/devcenter/iosand log in. UnderiOS Program program, choose Certificates, Identifiers & Profiles.



It's easiest to simply let Xcode handle all the certificate and provisioning profilestuff but you can also manage these things yourself from the iOS Dev Center. youcan download the handy App Distribution Guidethat explains how all of thisworks in detail.

This concludes the setup. You have added your Developer Program account toXcode, obtained a Development Certificate, registered your device, and installed aprovisioning profile. You're ready to run the app on your phone!

! Go back to Xcode's main window and click on the scheme selector in the toolbarto change where you will run the app. The name of your device shocould be in thatlist somewhere.

On my system it looks like this:


! PressRunto launch the app.

At this point you may get a popup with the question "codesign wants to sign usingkey... in your keychain ". if so, answer withAlways Allow. this is Xcode trying touse the new Development Certificate you just created but you need to give itpermission first.

Does the app work? Awesome! If not, read on...

There are a few things that can go wrong when you try to put the app on yourdevice, especially if you're 've never done this before, so don't panic if you run your problems.

The device is not connected. make sure your iPhone, iPod touch, or iPad isconnected to your Mac. the device must be listed in Xcode's Devices window andthere shoshould not be a yellow warning icon next to the device name.

The device is locked. If your phone locks itself with a passcode after a fewminutes, you might get this warning:


Or you might get a message in the Xcode Debug output pane:

Error: failed to launch "BullsEye '-- device locked

Simply unlock your phone (type in the 4-digit passcode) and press Run again.

No signing identity found. Your Development Certificate is not found, not valid, or is missing the corresponding private key. When this happens, Xcode will offer

Request a new certificate. You can also make the certificate yourself on the iOS Dev

Center and add it to Xcode in the Accounts preferences panel.

Code Sign error: a valid provisioning profile matching the application 'sidentifier' com. yourname. bullsEye 'could not be found. xcode does not havea valid provisioning profile for signing the app. the installation of the TeamProvisioning Profile has apparently failed.

No valid provisioning profile on the device. This really shouldn't happenbecause Xcode will automatically install the profile onto the device before it runsthe app, but you never know.

Xcode cocould not find a valid private-key/certificate pair for this profile inyour keychain. your development certificate isn' t properly installed. this canhappen when you moved your certificates to a new computer but forgot to movethe corresponding private keys as well.

The first step in solving such problems is to restart Xcode and try again. That 'salways good advice when Xcode does not do what you want.

If that doesn't help, open thePreferenceswindow and go to theAccountstab. select your account and click theView Detailsbutton. in the dialog that appears, click the refresh button (the arrow in the bottom-left corner ). xcode will now fetchyour data from the iOS Dev Center again.

Alternatively, open the Dev Center website in your browser (tip: it works best onSafari) and download the Provisioning Profile to your computer, then drag it ontothe Xcode icon. click on the Show Provisioning Profiles item under the name of thedevice and verify that the profile is installed on that device. if necessary, you canclick the + button to install the profile manually.

If you want to know how Xcode chooses which profile and certificate to sign yourapp with, then click on your project name and switch to theBuild Settingstab. there are a lot of settings in this list, so filter them by typingcode signin thesearch box. (Also make sureAllis selected, not Basic .)

The screen will look something like this:


UnderCode Signing Identityit saysDebug, Any iOS SDK: iPhone Developer. this is the certificate that Xcode uses to sign the app. if you click on that line, youcan choose another certificate. underProvisioning Profileyou can change theactive profile.

Xcode is actually pretty smart about automatically picking the right provisioningprofile for you, but now at least you know where to look.

Statement: This article is an abstract in the iOS Apprentice book. I want to translate the text above, but I have no time to allow it. I have to learn a lot of things. To prevent future use, you can take notes here. Thanks to the original author.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.