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 that
youmadeon 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 DeveloperProgram 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 DeveloperProgram account. There is a limit to how many devices you can register,
currentlyup to 100. This may sound like plenty – you probably don’t have a hundred iPhoneslying around – but this includes 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):

On the left is a list of devices that can be used for development.

!Click on your device name to select
it.

If this is the first time you’re using the device with Xcode, the Devices window willsay something like, “Matthijs’s iPad is not paired with your computer.”
To pair thedevice with Xcode, you need to unlock the device first (slide to unlock).

After unlocking, an alert will pop up on the device asking you to trust the computeryou’re trying to pair with. Tap onTrustto
continue.

Xcode will now refresh the page and let you use the device for development. Youmay need to unplug the device and plug it back in first.

At this point it’s possible to get the error message, “An error was encountered whileenabling development on this device.” You’ll need to unplug the device
and rebootit. Make sure to restart Xcode before you reconnect the device. (General tip: If yourun into weird problems, restarting Xcode usually fixes it.)

Cool, that is the device sorted.

The next step is setting up the Developer Program account with Xcode. At this pointI assume you’ve already registered and paid for the account and you
have yourApple ID and password handy.

!Open theAccountspane
in the Xcode Preferences window:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGVvY2hhbmcxMzA3MzE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" 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 DeveloperProgram account, creates a new Development Certificate, and downloads
andinstalls 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
the

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 DeveloperProgram,
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 should 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’ve never done this before, so don’t panic if you
run intoproblems.

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 should 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 to

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 could 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.

声明:此文为iOS Apprentice 书中文摘,本想翻译上面文字来着,无奈时间不同意,要学的东西,要做的事太多了。以备以后会用到,这里权当笔记记之。

感谢原作者。

Running the app on your device的更多相关文章

  1. Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment:

    Administrator@DESKTOP-EHCTIOR MINGW64 /d/react-native-eyepetizer (master) $ react-native run-android ...

  2. Running Your App(运行你的应用程序)

    如果你按照上一篇课程创建了android项目,它将包含helloworld的源文件,让你可以立即运行你的应用程序. 你如何运行你的应用程序app依赖于两件事: 你是否拥有一台真正的android设备 ...

  3. android studio使用真机测试时点击Debug调试模式时报Error running app:No target device found,点击运行模式却是启动正常的

    原因是adb没检测到设备(包括真机和虚拟机). 在Terminal执行adb devices命令,查看有没有连接到的设备. 如果没有设备,确认虚拟机是否正确打开,真机是否连接打开USB调试并安装驱动. ...

  4. 发布android apk,Error running app: No target device found.

    https://developer.android.com/studio/run/device.html\ 一台android设备不识别,android文档还挺全 需要安装usb驱动链接里有

  5. How Do I Deploy a Windows 8 App to Another Device for Testing?

    If your developing a new Windows 8 app and you want to test it on another device (e.g. Surface), you ...

  6. Testing your Xamarin app on Android device

    I've develop a test application in Xamarin Studio (Android with C#) and wanted to test it on my phon ...

  7. Installing your app on your Windows RT device

    Alright… so my app is almost finished and I want to install it for real on my Surface tablet. How do ...

  8. 为WIN8 APP创建置顶desktop应用

    Windows 8: TopMost window   I am working on my next ambitious project “MouseTouch” which is multi to ...

  9. App Store审核被拒的23个理由

    原文地址 iOS 应用提交审核要持续一周或者更久,在提交之前,我们一定要进行「自我审查」,避免被拒.ASO100 为大家收集整理了2015年 App Store 审核被拒的23个理由,并且附上官方拒绝 ...

随机推荐

  1. HDU 1054 Hungary

    Strategic Game Problem Description Bob enjoys playing computer games, especially strategic games, bu ...

  2. 一种压缩图片的方法---Machine learning 之 K-Means

    背景描述: RGB编码:对于一个直接用24bit表示每一个而像素的图像来说,每一个pixel使用8-bit无符号整数(0-255)来表示红or绿or蓝. 压缩目的: 将128x128大小的图片由原来的 ...

  3. spring框架搭建(一)

    spring介绍 spring是一个轻量级控制反转(IOC)和面向切面(AOP)的容器框架,它主要是为了解决企业应用开发复杂性而诞生的. 简单来说spring是一个一站式轻量级开源框架. IOC:In ...

  4. Java内存机制,内存地址

    问题一:String str1 = "abc"; String str2 = "abc"; System.out.println(str1==str2); // ...

  5. Java_Web之宠物管理系统

    使用JSP+servLet实现宠物管理系统,oraC1e11g作为后台数据厍,实现查看宠物和增加宠物的功能由你实现,如图: 其中宠物包栝:狗.猫.鸟.鼠 具体要求及推荐实现步骤 第一步:创建数据库代码 ...

  6. 蛮好用的局域网测试工具iperf

    公司局域网总是莫名其妙的和一台机器网速很慢,虽然无法解决也无人解决,但是能有个有效的测试至少也会心里有数. 咱干不了网络硬件布线的活,就测测网速吧. 网上找了下,开始有文章介绍NetIQ Chario ...

  7. change project compliance and jre to 1.5

    这个主要检查一下几点 项目的jdk为1.7 java版本设置为1.7 java compiler 的页面设置为以下,并且去掉勾选java compiler 下面的 enableproject spec ...

  8. Oracle中REGEXP_SUBSTR函数

    Oracle中REGEXP_SUBSTR函数 Oracle中REGEXP_SUBSTR函数的使用说明: 题目如下: 在oracle中,使用一条语句实现将'17,20,23'拆分成'17','20',' ...

  9. Phpstudy apache2 配置 https

    我tm竟然搞了一下午 最终原因是因为443 端口被 SVN服务器占用了 一定要查看端口是否被占用 太深刻了这次 粗心大意 !!! 1:打开PHPstudy php扩展设置,在php_openssl上点 ...

  10. react功能实现-数组遍历渲染

    在react中如何将一个数组遍历,并且逐个渲染在页面上? 1.在jsx渲染中,如果这个变量是一个数组,则会展开这个数组的所有成员. var arr = [ <h1>Hello world! ...