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 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的更多相关文章
- 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 ...
- Running Your App(运行你的应用程序)
如果你按照上一篇课程创建了android项目,它将包含helloworld的源文件,让你可以立即运行你的应用程序. 你如何运行你的应用程序app依赖于两件事: 你是否拥有一台真正的android设备 ...
- android studio使用真机测试时点击Debug调试模式时报Error running app:No target device found,点击运行模式却是启动正常的
原因是adb没检测到设备(包括真机和虚拟机). 在Terminal执行adb devices命令,查看有没有连接到的设备. 如果没有设备,确认虚拟机是否正确打开,真机是否连接打开USB调试并安装驱动. ...
- 发布android apk,Error running app: No target device found.
https://developer.android.com/studio/run/device.html\ 一台android设备不识别,android文档还挺全 需要安装usb驱动链接里有
- 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 ...
- 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 ...
- 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 ...
- 为WIN8 APP创建置顶desktop应用
Windows 8: TopMost window I am working on my next ambitious project “MouseTouch” which is multi to ...
- App Store审核被拒的23个理由
原文地址 iOS 应用提交审核要持续一周或者更久,在提交之前,我们一定要进行「自我审查」,避免被拒.ASO100 为大家收集整理了2015年 App Store 审核被拒的23个理由,并且附上官方拒绝 ...
随机推荐
- POJ 1111(数字很吉利嘛) 简单BFS
Image Perimeters Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8594 Accepted: 5145 Desc ...
- PHP 二维数组排序 可以按指定 键值排序
<?php header("Content-Type:utf-8"); $arr = array( 0 => array( 'name' => '国际原油价格', ...
- Lua eval实现
因为loadstring总是在全局环境中编译它的串,所以编译出的函数访问的变量是全局变量.为了避免污染全局环境我们需要用setfenv修改函数的环境 function eval(equation, v ...
- ArrayList<HashMap<String,Object>>集锦
1. Android中如何从一个Activity中ArrayList<HashMap<String,Object>>传递到另一个activity? eg: ...
- 【Oracle】DG中物理备库、快照备库的相互转换
一.物理备库切换快照备库 1. 如果正在运行日志应用,先停止 ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; 2. 确保数据库为MOUN ...
- MyEclipse加入jquery.js文件missing semicolon的错误
今天打开项目,发现有一个小红叉,虽然不影响项目的编译和运行,但是看着非常影响心情.原因是jquery-1.8.2.min.js报了一堆missing semicolon的错误.之所以会这样,其实是My ...
- SQLite-编译指示
SQLite – 编译指示 SQLite编译指示命令(PRAGMA)是一个特殊的命令是用于控制各种环境变量和状态标志在SQLite的环境.编译指示值可以读取,也可以根据需求设置. 语法: 查询当前的编 ...
- HDU_5724_状态压缩的sg函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5724 题目大意:n行20列的棋盘,对于每行,如果当前棋子右边没棋子,那可以直接放到右边,如果有就跳过放 ...
- 八进制、十进制、操作符(day04)
把二进制表示的数字从右向左每三个数位分成 一组,每组用一个0到7之间的数字替换. 这个替换结果叫做数字的八进制表示方式 (八进制) 可以直接在程序里用八进制方式表示数字, 这种数字必须以0做开头 可以 ...
- 自己总结的php开发中用到的工具
需要一个编辑器IDE,推荐用phpstorm. IDE安装完了,还要搞个Xdebug,这个很有用,程序断点跟踪调试就靠他了. phpstom平时使用的时候,编辑界面感觉很枯燥的时候,可以换个主题,换主 ...