DEVICES The Devices and iPhone Development groups in the organizer are designed specifi cally to support the special needs of iPhone and iPod developers. Much of the information in these two groups overlap. The difference is in their perspective; the Devices group displays information about actively connected devices, whereas the iPhone Development group — described in a later section — aggregates historical development information from all of your devices. Adding and Removing Devices iPhone and iPod Touch devices are automatically added to the organizer whenever you connect one to your computer while Xcode is running. Once added, they persist until removed from the organizer. The organizer shown in Figure 22 - 6 has had two devices added. The device named “ iPhone ” is currently connected, as indicated by the green dot next to its name, whereas the device named “ Tea tray ” is not. FIGURE 22 - 6 The activities in the Devices group interact directly with the connected device. A device that ’ s not connected does little but display the message “ This device is not currently connected. ” You ’ ll see the identity of the device and you can browse previously downloaded crash reports — but that ’ s about it. To remove an obsolete device from your organizer, Right/Control+click the device name and choose the Remove From Organizer command. You can also have Xcode ignore a particular device, such as a personal iPod that you do not use for development. To do that, plug in the device and choose the Ignore Device command from the same menu. You interact with your development device by connecting it to your computer, selecting it in the organizer, and then choosing the desired tab that appears in the details pane. The tabs are Summary, Crash Logs, Console, and Screenshots. The functions of each are described in the next few sections. Devices ❘ 629 c22.indd 629c22.indd 629 1/21/10 4:38:26 PM1/21/10 4:38:26 PM Download at getcoolebook.com 630 ❘ CHAPTER 22 USING THE ORGANIZER The Summary tab shows the name, serial number, unique device identifi er (UDID), and the version of the operating system installed on your device. You ’ ll need the UDID to register your device for development. You can obtain it by copying text from the details pane, or by Right/Control+clicking the device name in the Devices group and choosing the Copy Device Identifi er command. For the sake of brevity, both the organizer and this book use the generic term “ iPhone ” to mean any iPhone, iPod Touch, or similar device that ’ s supported by Xcode. This is not a slight to any iPod Touch users nor is it meant to exclude any future Apple devices. Installing Provisioning Profi les Before you can get started doing any kind of iPhone development — or more precisely, before you can begin to do any Apple-sanctioned iPhone development on an Apple device — you must provision your iPhone. Provisioning is basically the installation of a set of digital signatures, some that you generate and others obtained from Apple, that authorize your iPhone to execute your application for the purposes of development. The iPhone will refuse to install or launch an application that has not been digitally signed by both its author (that ’ s you) and Apple. The process of provisioning is adequately explained in both the iPhone Development Guide , included in the Xcode documentation, and in the instructions in the iPhone Developer Program Portal, the web site you ’ ll use to obtain provisioning profi les. Nevertheless, I ’ ll summarize the steps here: 1. Join the iPhone Developer Program. This is a requirement for accessing the iPhone Developer Program Portal. 2. If you ’ ve joined the iPhone Developer Program as an organization, you — or someone — must defi ne the team members allowed to use the iPhone Developer Program Portal, hereafter just called the Portal. 3. Follow the instructions at the Portal for using the Keychain Assistant to create a certifi cate signing request (CSR). This is a digitally signed request that contains your offi cial identity. 4. Upload your CSR to the Portal. Review the request and approve it. 5. Apple then creates a development certifi cate , which is digitally signed by both you and Apple. An iPhone uses these signatures to determine the authenticity of an application. 6. Download the development certifi cate and install it on your keychain. If you need to do iPhone development using other computers or accounts, you will have to transfer copies of your private key (the one used to create the CSR) and your development certifi cate to those computers. 7. Make backups of your private key and development certifi cate and put them in a safe place, or places. 8. With the development certifi cate in place, you can now authorize individual devices for development. Plug each device into Xcode and use the organizer to obtain its Unique Device Identifi er (UDID). Copy your device ’ s UDID to the clipboard by selecting the ID in the Summary tab, or Right/Control+click on the device name and choose the Copy Device Identifi er command. Register your device in the Portal. c22.indd 630c22.indd 630 1/21/10 4:38:26 PM1/21/10 4:38:26 PM Download at getcoolebook.com 9. Create an application identifi er for the application you want to run on your registered development iPhone. Your application ’ s identifi er is a combination of a reverse - DNS name that you assign and a Bundle Seed ID generated by the Portal. An example would be 8E945J6902.com.wiley.proxcode.iPrime . In the Properties tab of the app target of your project, set the Identifi er fi eld to be the same identifi er, without the Bundle Seed ID. In this example, the application identifi er must be set to com.wiley.proxcode.iPrime . 10. Register you application ID with the Portal. 11. With all the preliminaries out of the way, you can now use the Portal to generate provisioning profi les. A provisioning profi le combines your development certifi cate, developer identity, device identity, and application identifi er. It defi nes what combination of developers and devices your application is permitted to run on, to be debugged on, and similar development privileges. 12. Download the provisioning profi le from the Portal. Once you ’ ve obtained one or more provisioning profi les, you need to install them into your development device. Plug in and select the device in the organizer. Either drag the provisioning profi le document into the Provisioning list of the Summary tab, or click the + button below the list of provisioning profi les, as shown in Figure 22 - 7, and choose the provisioning profi le to install. FIGURE 22 - 7 You ’ re likely to create a new provisioning profi le for each application you develop, although it ’ s possible to create a wildcard profi le that provisions multiple applications with similar IDs. To remove a provisioning profi le from the device, select it and click the – button. Managing Development Applications The next section in the Summary tab lists the applications that you have installed on your device, as shown in Figure 22 - 8. This list includes applications from Apple and other vendors, in addition to the applications that you ’ ve installed during development. The only applications that you can affect here are those that you ’ ve installed for development purposes. To remove any commercial applications, do so using the device or iTunes. Devices ❘ 631 c22.indd 631c22.indd 631 1/21/10 4:38:27 PM1/21/10 4:38:27 PM Download at getcoolebook.com 632 ❘ CHAPTER 22 USING THE ORGANIZER Normally your applications get installed on your device as a consequence of development. Whenever you run or debug an iPhone app on a device, Xcode fi rst downloads and installs the application before starting it. For whatever purpose, you can also install applications you ’ ve built (and provisioned) manually. Click the + button and select the application bundle to install. The application is installed immediately. The more useful feature is the ability to remove applications that you ’ re done developing. Select an application and click the – button. After removing the application, you ’ ll probably want to remove its provisioning profi le as well. Downloading Application Data Each iPhone application has a private directory in which it can store data, user preferences, and resources. To access this data, expand the application to expose its Application Data package, also shown in Figure 22 - 8. Next to the package is a download button. Click this button to extract the application ’ s private directory from the device and save it on your local drive. The package is automatically expanded and appears as a folder of fi les. Installing Alternate Operating Systems During development, you will want to test your application against different versions of the operating system. The currently installed operating system on your device appears in the pop - up menu in the Summary tab. If you have other iPhone OS SDKs installed, select one from the menu. Apple also makes pre - release or seed versions available to developers from time to time. If you ’ ve downloaded one of these software seeds, select it by choosing the Other Version command in the OS version menu, as shown in Figure 22 - 9. FIGURE 22 - 8 c22.indd 632c22.indd 632 1/21/10 4:38:28 PM1/21/10 4:38:28 PM Download at getcoolebook.com After choosing a new OS, click the Restore iPhone/iPod button next to it. Xcode will erase your device — deleting all applications and data — and install the selected operating system. You can now install and test your application. Installing a different OS erases everything on your device. If you have applications or data you want to preserve, fi rst synchronize your device with iTunes. iTunes will make a backup of your device. After testing, launch iTunes again. In the Summary tab for the device, click the Restore button and do not request another backup. After your device has been reset, select an existing backup. iTunes will restore your device and all of its data. Reviewing Crash Logs The Crash Logs tab lets you examine any crash logs or panic reports that have been downloaded from the device, as shown in Figure 22 - 10. Crash logs are automatically downloaded by the organizer and iTunes. FIGURE 22 - 9 FIGURE 22 - 10 Devices ❘ 633 c22.indd 633c22.indd 633 1/21/10 4:38:28 PM1/21/10 4:38:28 PM Download at getcoolebook.com 634 ❘ CHAPTER 22 USING THE ORGANIZER This is the actual running console log, downloaded from the connected device. If you have an application running on your device, you can check the console log for messages in real time. The console log doesn ’ t update automatically; click the Reload button to fetch any new messages. Much like the Console application in Mac OS X, you can clear the log, save a selected portion of the log to a text fi le, or fi lter the contents of the log using the search fi eld above the pane. The search fi eld performs both case - sensitive and case - insensitive searches. Use the console to fi nd diagnostic messages output by your application while it ’ s running. Note that when you run or debug an app via Xcode, the output of NSLog() and similar functions is redirected to the Run Console window of the project. These messages will also appear in the console log of the device, but you don ’ t have to open the console log to fi nd them. FIGURE 22 - 11 You can browse a report by selecting it in the list. Right/Control+click a report to delete it or reveal its text fi le in the Finder. Monitoring the Device ’ s Console Like Mac OS X, the iPhone OS also has a console log. This is the collection point for diagnostic messages emitted by iPhone applications and other processes. The Console Logs tab, as shown in Figure 22 - 11, reads the console log from the device. c22.indd 634c22.indd 634 1/21/10 4:38:32 PM1/21/10 4:38:32 PM Download at getcoolebook.com Capturing Screenshots and the Default Image The Screenshots tab displays the screenshots that been captured for this device, let s you take a screenshot, and will automatically install a screenshot as the default — that is, launch screen — for an iPhone application. Screenshots are useful for documenting your application, sharing results with other developers, and examining interface anomalies. The Screenshots tab is divided into two panes, as shown in Figure 22 - 12. One the left are all of the screenshots collected for this device. On the right you can view a selected screenshot or take a new screenshot. FIGURE 22 - 12 To take a screenshot, run your application and arrange the screen to your liking. In the Xcode organizer, click the Capture button. Xcode instructs the device to take a screenshot and then downloads it into the organizer. You can browse previously taken screenshots on the left. Select a screenshot to view it full size. You can also do any of the following: Drag a screenshot into the Finder to copy the screenshot fi le. Press Delete, or Right/Control + click and choose the Delete Screenshot command, to delete a screenshot. Install the screenshot as the Default screen for an iPhone application. ➤ ➤ ➤ Devices ❘ 635 c22.indd 635c22.indd 635 1/21/10 4:38:33 PM1/21/10 4:38:33 PM Download at getcoolebook.com 636 ❘ CHAPTER 22 USING THE ORGANIZER The default screen of an iPhone application is an image fi le that appears while the application is still loading. It can be used to present an entertaining splash screen or annoy users with crass advertising, but it ’ s often used to make the application appear to load faster than it really does. This last trick is accomplished by making a screenshot of the initial view of your application with no content, and then installing that as the default image. When the user taps your app, a full - fl edged interface appears (without content) almost immediately. What ’ s really happening is the application is still launching while the user is looking at the default image. As soon as the app starts up, the display seamlessly refreshes. To create this bit of prestidigitation, follow these steps: 1. Open your iPhone application project. 2. Run your application on the device and wait until its fi rst window appears, with no content. 3. In the organizer, take a screenshot. 4. Click the Save As Default Image button and choose your Xcode project. The Save As Default Image button adds a Default.png fi le to your project ’ s Resources group. Of course, you could have done this yourself, and you ’ re free to provide any kind of Default.png fi le that you want. Screenshots taken in the organizer and screenshots taken using your device are not intermingled. If you’ve taken a screenshot on the device — by holding down the sleep and home buttons — use iPhoto to download the image fi le. You can then import it into your project. iPHONE DEVELOPMENT The iPhone Development group is largely a rehashing of local and historical information that you ’ ve already seen in the Devices group. The key difference is that the information in the iPhone Development group is obtained from your local system and applies to all of your devices, connected or not. Crash Logs The Crash Logs group is an aggregate list of all the crash logs from all of your devices. It functions the same way the Crash Logs tab in the Devices group does. Provisioning Profi les This group lists the status of all of the provisioning profi les you ’ ve installed on your system, as shown in Figure 22 - 13. c22.indd 636c22.indd 636 1/21/10 4:38:33 PM1/21/10 4:38:33 PM Download at getcoolebook.com Select a profi le to display its details and the list of devices where it is currently installed. Press Delete or Right/Control+click a profi le and choose the Delete Profi le command to permanently delete a provisioning profi le from your system. You can also choose the Reveal Profi le in Finder command to locate the fi le. Screenshots This group is identical to the Screenshots tab of an individual device, except that it shows all of the screenshots captured in the organizer. Software Images Finally, the Software Images group lists the operating system packages that are installed on your system. These are the packages that allow you to install different versions of the iPhone OS on your device. See the “ Installing Alternate Operating Systems ” section, earlier in this chapter. SUMMARY The organizer is a powerful new addition to Xcode that let s you organize your project, devices, and tasks at a level above your individual projects. By customizing and sharing actions you automate repetitive workfl ow and can share those solutions with other developers. You now know how to connect, register, and interact with your iPhone and iPod Touch devices. The fi nal chapter turns to what many consider to be an endless source of joy and entertainment: tweaking obscure options and settings in Xcode, customizing it to suit your every whim. FIGURE 22 - 13 Summary ❘ 637 c22.indd 637c22.indd 637 1/21/10 4:38:39 PM1/21/10 4:38:39 PM Download at getcoolebook.com c22.indd 638c22.indd 638 1/21/10 4:38:40 PM1/21/10 4:38:40 PM Download at getcoolebook.com . settings in Xcode, customizing it to suit your every whim. FIGURE 22 - 13 Summary ❘ 637 c22.indd 637 c22.indd 637 1/21/10 4 :38 :39 PM1/21/10 4 :38 :39 PM Download at getcoolebook.com c22.indd 638 c22.indd. profi les you ’ ve installed on your system, as shown in Figure 22 - 13. c22.indd 636 c22.indd 636 1/21/10 4 :38 :33 PM1/21/10 4 :38 :33 PM Download at getcoolebook.com Select a profi le to display its. iTunes. FIGURE 22 - 9 FIGURE 22 - 10 Devices ❘ 633 c22.indd 633 c22.indd 633 1/21/10 4 :38 :28 PM1/21/10 4 :38 :28 PM Download at getcoolebook.com 634 ❘ CHAPTER 22 USING THE ORGANIZER This is the