www.it-ebooks.info www.it-ebooks.info iPhone® and iPad® App 24-Hour Trainer Introduction xxv LESSON Hello iOS! LESSON The iOS Simulator 17 LESSON A Tour of Xcode 21 LESSON iOS Application Basics 39 LESSON Introduction to Storyboards 61 LESSON Handling User Input 81 LESSON Communicating with Your Users 93 LESSON Adding Images to Your View 103 LESSON Pickers 111 LESSON 10 Date Pickers 119 LESSON 11 Custom Pickers 127 LESSON 12 Navigation Controllers 135 LESSON 13 Table Views 147 LESSON 14 Static Table Views 161 LESSON 15 Tab Bars and Toolbars 173 LESSON 16 Creating Page-Based Applications 187 LESSON 17 Creating UI Elements Programmatically 197 LESSON 18 Creating Views That Scroll 205 LESSON 19 Popovers and Modal Views 217 LESSON 20 Tweeting with Twitter 231 LESSON 21 Basic File Handling 239 LESSON 22 Property Lists 249 LESSON 23 Application Settings 259 LESSON 24 iTunes File Sharing Support 269 LESSON 25 Introduction to iCloud Storage 277 www.it-ebooks.info LESSON 26 Introduction to Core Data 303 LESSON 27 XML Parsing with NSXMLParser 317 LESSON 28 Consuming SOAP Web Services 335 LESSON 29 Touches and Gestures 349 LESSON 30 Printing 359 LESSON 31 Basic Animation with Timers 367 LESSON 32 Introduction to Core Image 375 LESSON 33 Building Universal Applications 383 LESSON 34 Where Am I? Introducing Core Location 391 LESSON 35 Introducing Map Kit 403 LESSON 36 Using the Camera and Photo Library 413 LESSON 37 Introduction to Core Motion 421 LESSON 38 Building Background-Aware Applications 435 appendix A What’s on the DVD? 447 Index 451 ⊲⊲ Bonus Material Appendix B Introduction to Programming with Objective-C Appendix C Introduction to ARC 37 Appendix D Testing on an iOS Device 55 Appendix E Ad Hoc Distribution 65 Appendix F App Store Distribution 75 www.it-ebooks.info iPhone® and iPad® App 24-Hour Trainer www.it-ebooks.info www.it-ebooks.info iPhone and iPad App 24-Hour Trainer ® Abhishek Mishra Gene Backlin www.it-ebooks.info ® iPhone® and iPad® App 24-Hour Trainer Published by John Wiley & Sons, Inc 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana ISBN: 978-1-118-13081-0 ISBN: 978-1-118-22507-3 (ebk) ISBN: 978-1-118-23837-0 (ebk) ISBN: 978-1-118-26314-3 (ebk) Manufactured in the United States of America 10 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600 Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http:// www.wiley.com/go/permissions Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose No warranty may be created or extended by sales or promotional materials The advice and strategies contained herein may not be suitable for every situation This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services If professional assistance is required, the services of a competent professional person should be sought Neither the publisher nor the author shall be liable for damages arising herefrom The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002 Wiley publishes in a variety of print and electronic formats and by print-on-demand Some material included with standard print versions of this book may not be included in e-books or in print-on-demand If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport wiley.com For more information about Wiley products, visit www.wiley.com Library of Congress Control Number: 2012930548 Trademarks: DVD and software compilation copyright © 2012 John Wiley & Sons, Inc All rights reserved Individual programs are copyrighted by their respective owners and may require separate licensing This DVD may not be redistributed without prior written permission from the publisher The right to redistribute the individual programs on the DVD depends on each program's license Consult each program for details Wiley, Wrox, and the Wrox logo are trademarks or registered trademarks of John Wiley & Sons, Inc and/or its affiliates, in the United States and other countries, and may not be used without written permission iPhone and iPad are registered trademarks of Apple, Inc All other trademarks are the property of their respective owners John Wiley & Sons, Inc is not associated with any product or vendor mentioned in this book www.it-ebooks.info To my wife Sonam, for her love and support through all the years we’ve been together —Abhishek Mishra This book is being dedicated to the family unit, past, present and future May it never lose sight of its existence —Gene Backlin www.it-ebooks.info www.it-ebooks.info Configuring Your Project for Distribution Figure E-13 www.it-ebooks.info ❘ 73 www.it-ebooks.info F App Store Distribution In most cases, after your app is ready and tested, you will want to list it on the App Store Regardless of your pricing strategy (free or paid), every application that is submitted to Apple for distribution via the App Store is subject to an approval process The approval process takes about a week Updated versions of an existing application also need to go through an approval process To distribute your application via the App Store, you will need a standard, paid, iOS developer account If you have an enterprise iOS developer account, you cannot distribute your applications through the App Store Submitting an application to Apple for inclusion in the App Store is a two-stage process First, you need to create an Application Profile on the iTunes Connect portal, and then you need to submit your application binary with the Xcode Organizer Most of the steps involved in the second stage of creating and submitting the application binary are similar to the Ad Hoc distribution process, and these steps are covered only briefly in this appendix Creating an Application Profile To start the App Store submission process, log in to the iTunes Connect portal at https:// itunesconnect.apple.com/ with your iOS developer account credentials Once you have logged in to the portal, click the Manage Your Applications link (Figure F-1) On this screen you will see all your iOS and MacOS applications You can either add a new application, or manage one of the existing ones To create a new Application Profile, click the Add New App button on the top-left corner of the window (Figure F-2) You will be asked to select the type of application you want to submit (iOS or MacOS) Selecting the iOS App option will take you to the Application Information screen (Figure F-3) On this screen you need to specify basic information on the app including an application name, a SKU code, and an application Bundle Identifier Creating and registering Bundle Identifiers was covered in Appendix D www.it-ebooks.info 76 ❘ APPENDIX F App Store Distribution Figure F-1 Figure F-2 You will also need to enter a Bundle ID Suffix and verify that the bundle identifier specified in your Xcode project’s info.plist file matches what is specified on this screen The Bundle ID Suffix is typically the name you used while creating the Xcode project The SKU code is not used by Apple, but is used to identify the application on the monthly financial report provided by Apple Click Continue when you have finished entering this information www.it-ebooks.info Creating an Application Profile ❘ 77 Figure F-3 The next part of the process requires you to specify availability date and pricing information The pricing category you select will affect the price your end users pay for your application If you not want your application to be available across all App Stores worldwide, you can select specific countries on this screen (Figure F-4) by clicking the Specific Stores link and then selecting individual stores Figure F-4 www.it-ebooks.info 78 ❘ APPENDIX F App Store Distribution Click Continue to go to the next screen, where you will provide detailed information on the application This is a large screen and consists of the following sections: ➤➤ Metadata ➤➤ Rating ➤➤ EULA ➤➤ Uploads The Metadata section resembles Figure F-5 Here you need to specify the following information: ➤➤ Version Number: This must match the value set in the Xcode project ➤➤ Description: This is the description as you want it to appear on the App Store It can be no more than 4000 characters ➤➤ Primary Category: Select a category that best describes the app you are adding from a list of available categories ➤➤ Subcategory: Some categories (like Games) allow you to specify up to two subcategories ➤➤ Secondary Category: An additional category that further describes the app you are adding ➤➤ Keywords: One or more keywords that describe the app you are adding When users search the App Store, the terms they enter are matched with these keywords ➤➤ Copyright: The name of the person or entity that owns the copyright to the app ➤➤ Contact Email Address: An email address where Apple engineers can contact you if there are problems with your app ➤➤ Support URL: A URL that links to the application’s support site ➤➤ App URL: An optional URL that links to the application’s website ➤➤ Privacy Policy URL: An optional URL that links to the application’s privacy policy page ➤➤ Reviewer Notes: Optional notes intended for the person reviewing the application at Apple If your application uses any online services and requires its users to provide credentials to access these services, you can provide a set of test credentials here for the reviewer to use The Rating section consists of a series of questions, the answers to which determine a rating category for your application (Figure F-6) The rating determines the parental controls that will apply to your application As you change the answers to these questions, the age limit will change The EULA section allows you to provide a specific end-user license agreement for specific countries If you not provide one, the standard license agreement will apply The Uploads section allows you to upload a few images for your application (Figure F-7) These images are: ➤➤ Large 512 n 512 Icon: A 512 n 512 pixel image that is similar to the application icon and will be used while listing your application on the App Store www.it-ebooks.info Creating an Application Profile ❘ 79 ➤➤ iPhone and iPod Touch Screenshots: You can upload up to five images These must be 320 n 480 pixels for portrait applications and 480 n 320 pixels for landscape applications ➤➤ iPad Screenshots: You can upload up to five images These must be 768 n 1024 pixels for portrait applications and 1024 n 768 pixels for landscape applications Figure F-5 Figure F-6 www.it-ebooks.info 80 ❘ APPENDIX F App Store Distribution Figure F-7 If you are submitting a universal application, you will need to provide both iPhone and iPad screenshots Click the Next button at the bottom of the screen to finish creating the Application Profile You are then taken to the App Summary screen, where you should review the information presented and click Done Preparing and Uploading the Application Binary Once you have created the Application Profile, the next step involves preparing and uploading the actual binary You can this immediately after creating the Application Profile or later on If you decide to it later on, you will need to log in to the iTunes Connect portal and click the Manage Your Applications link to come to the screen that lists all your applications (Figure F-8) If you’ve decided to proceed immediately after creating the Application Profile, you should be at this screen now www.it-ebooks.info Preparing and Uploading the Application Binary ❘ 81 Figure F-8 You should find your new application listed there Click your application’s icon to access the App Summary screen The App Summary screen enables you to modify rights and pricing information, configure In-App purchases, Game Center, News Stand, and iAd Network settings You can also delete the app from this screen Toward the bottom of the screen you will see a list of versions for the application, along with status information Because this is a new application, there is only one entry in this list corresponding to version 1.0 Click the View Details link to go to the details page for this version (Figure F-9) Figure F-9 www.it-ebooks.info 82 ❘ APPENDIX F App Store Distribution On the Version Details screen you can edit metadata, update screenshots, configure localization options for your application, and update its status Click the Ready to Upload Binary button on this screen (located in the top-right corner) You will be asked to verify that you are not exporting encryption software, and if you are you will need to provide answers to additional questions Select the appropriate options and click the Save button Click the Continue button on the next screen to go back to the Version Details screen, and note that your application’s status has changed to “Waiting for Upload.” You can sign out of the iTunes Connect portal at this point if you wish The rest of the process involves building the application binary and uploading it to the iTunes Connect portal using the Xcode Organizer If you haven’t done so already, you will need to create and install a distribution certificate This process is covered in detail in Appendix D Creating an App Store Distribution Provisioning Profile If this is the first application you are submitting to the App Store, you will need to create an App Store distribution provisioning profile A provisioning profile associates an App ID, a certificate, and some distribution-specific information within Xcode To create an App Store distribution provisioning profile, log in to the iOS Provisioning Portal, click the Provisioning category on the left side, and select the Distribution tab Here you will see a list of existing distribution provisioning profiles To create a new one, click the New Profile button Set the distribution method to App Store (Figure F-10) and provide a descriptive name for the new profile Select an App ID and click the Submit button to create the provisioning profile Figure F-10 www.it-ebooks.info Preparing and Uploading the Application Binary ❘ 83 Your provisioning profile is issued automatically, and is available to download in a few minutes You may need to refresh your browser window Download the distribution provisioning profile onto your Mac and install it by dragging the mobileprovision file onto Xcode in your dock Configuring Your Project for App Store Distribution The final step in the process involves setting up your Xcode project and preparing an appropriate build Before you begin, make sure you have installed both your distribution certificate and App Store distribution provisioning profile To check, simply bring up the Xcode Organizer by clicking the last button in the Xcode toolbar and select Provisioning Profiles in the Organizer menu If you have successfully installed your App Store distribution provisioning profile and distribution certificate, your profile should be listed in the Organizer without any error messages in the Status column Once you have verified that no errors are reported by the Organizer, close it and load the project that you want to prepare for App Store distribution If the project’s App ID is different from what has been registered with the iOS Provisioning Portal, edit the value of the Bundle Identifier key in the project’s info.plist file to match Save the info.plist file if you have edited it, and then ensure that the Scheme/Target selector in the Xcode toolbar is set to build for an iOS Device Access the project’s properties by selecting the root project node in the project navigator Select the build target and then switch to the Build Settings tab Scroll down to the Code Signing section and locate the node that corresponds to the Release configuration Under this node, you will find a node labeled Any iOS SDK Ensure the value of this node is set to be the App Store distribution provisioning profile you created and installed earlier (Figure F-11) Figure F-11 Select the Edit Scheme menu from the Scheme/Target multi-selector in the Xcode toolbar (Figure F-12) In the Edit Scheme dialog box, select Archive from the left menu to bring up archive-specific options Ensure the Reveal www.it-ebooks.info Figure F-12 84 ❘ APPENDIX F App Store Distribution Archive in Organizer option is checked and the Build Configuration is set to Release (Figure F-13) Click OK to dismiss this dialog Figure F-13 At this point you are ready to prepare an archive that can be distributed to your clients/beta-testers To prepare an archive, simply select the Product d Archive menu item in Xcode This builds your project for App Store distribution During the build process, Xcode may ask you to allow access to your development certificate If it does, click the Allow button When the archive is successfully built, the Organizer opens automatically, revealing the archive To submit the archive to the iTunes Connect portal, ensure the relevant archive is selected, and click the Submit button The Organizer will ask you for your iTunes Connect login credentials, and present a simple list of applications in the “Waiting for Upload” state (Figure F-14) Ensure the correct Application Profile is selected, and click Next Once again, you may be prompted to allow access to your Distribution Certificate; if so, click Allow In a few seconds you are presented with a message confirming that the archive has been submitted for approval www.it-ebooks.info Preparing and Uploading the Application Binary Figure F-14 www.it-ebooks.info ❘ 85 www.it-ebooks.info Try Safari Books Online FREE for 15 days + 15% off for up to 12 Months* Read this book for free online—along with thousands of others— with this 15-day trial offer With Safari Books Online, you can experience searchable, unlimited access to thousands of technology, digital media and professional development books and videos from dozens of leading publishers With one low monthly or yearly subscription price, you get: • Access to hundreds of expert-led instructional videos on today’s hottest topics • Sample code to help accelerate a wide variety of software projects • Robust organizing features including favorites, highlights, tags, notes, mash-ups and more • Mobile access using any device with a browser • Rough Cuts pre-published manuscripts START YOUR FREE TRIAL TODAY! Visit my.safaribooksonline.com/wrox43 to get started *Available to new subscribers only Discount applies to the Safari Library and is valid for first 12 consecutive monthly billing cycles Safari Library is not available in all countries www.it-ebooks.info ... Appendix F App Store Distribution 75 www.it-ebooks.info iPhone and iPad App 24- Hour Trainer www.it-ebooks.info www.it-ebooks.info iPhone and iPad App. .. www.it-ebooks.info www.it-ebooks.info iPhone and iPad App 24- Hour Trainer ® Abhishek Mishra Gene Backlin www.it-ebooks.info ® iPhone and iPad App 24- Hour Trainer Published by John Wiley & Sons, Inc 10475... the iPhone (simply known as iPhone OS back then), and was subsequently extended and renamed in June 2010 to iOS to support the iPad, iPhone, and iPod Touch iOS at its core is Unix-based, and