BOOKS FOR PROFESSIONALS BY PROFESSIONALS® CHAPTER 9 S A E L TIT p D Apple Watch for Developers: Advice & Techniques from TE Branches p A Five Top Professionals gives you the base-knowledge EL l R and valuable secrets you’ll need for your own projects e from a core team of successful, experienced Apple Watch W app-development experts. You’ll explore elements such as branding within Watch apps, translating audio data a into visual information, taming complex data, mastering t c When the APEX server reecneviivreosn am seunbtm-ditr irveeqnu feesat tfurorem s ae tbsr, oawnsde mr, iut cphe rmfoormre.s the h validations and processes associated with that request. Its final task is to choose a target This book is for developers who already have basic page to send to the browser. By default, APEX chooses the page that was submitted, but it f knowledge of developing with WatchKit and WatchOS 2, o is possible to specify another page by creating a branch . and who are now interested in learning how to use them r You have been able to get this far through the book without needing to use branches because of the ease in wthoic chr emautelt icpulet trienggio-ends gcaen W baet ccrhe aatpedp so. nIt a i sp awgrei tatnedn tbhye wfivaey that D these regions can be conedxiptieorniealnlyc eredn Adperpelde tWo agtivceh tdheev eeffleocpte orfs m wuhloti phlea vpea gceres.a Bteudt there e are many situations in wthhiechir aanp paps palsic paatirotn o wf Aillp upslee ’ms buelttiap lpe rpoaggreasm to, aimndp laerme ennot wa user v activity. In this chapter, yreoaud iny vteos tdigeactoen tshter uucste eoxf abmrapnlcehs etso t osh souwpp yoorut t hhoeswe stoit ubaetsiot ns. e create your own Apple Watch app. This book will bring l o your innovative Watch ideas to life! Separating Input from Output p You’ll learn how to: e Apple Watch for AA cuosemr menotne rasp ipnlpicuat toionn a d peas•gi ge An a ctncedec hpcnlti ciaqknusd ea ihbsa utontt dounlsee; tvsheoepi caaepra prteleicc poaatgigonensit tfiohoren ni no bpnru attnh acenh de s o utot put . rs Apple Watch another page that displays the output. As an example of this •te Bchenstiq sueen, dco dnastiad ebra tchke atwnod pfoagrtehs sfrhoomwn iC inlo Fuidgures 9-1 and 9-2 . The pages have a •s i n Pgelref orergmio fnu enaccthio annsd t whaotr kt askime ivlaerrlyy tfoe wth eta spinsg le Filter by Job and Department page oof Cf ah aspctreere 6n . In particular, a user begins on the Filter and Branch page shown in Figu•r e L 9e-v1e , rcahgoeo sfrinegq ua ejonbc ya ndde dteecptaiortnment from the select lists and then clicking a button•. T Rhuen s yysoteumr a thpepns bnraatnivcehleys oton t thhee F Wilattecrhed Employees page Developers of Figure 9-2 , which displa•y s W a orerpko wrti tohf eAmpppl oGyreoeusp wsh too hsaevned t haantd jo rbe caenidv ea rdea itna that department. • Interface with synced Twitter accounts R ic h e s M K loar stetin Advice & Techniques from Five Top Professionals re mz an Jr. G M Gary Riches Ruben Martinez Jr. Jamie Maison ra ifis finon Matt Klosterman Mark Griffin ISBN 978-1-4842-1339-1 53499 US $ 34.99 1 Shelve in SOURCE CODE ONLINE Mobile Computing www.apress.com User level: Intermediate–Advanced 9781484213391 www.it-ebooks.info For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. www.it-ebooks.info Apple Watch for Developers Advice & Techniques from Five Top Professionals (cid:132)(cid:132)(cid:132) Gary Riches Ruben Martinez Jr. Jamie Maison Matt Klosterman Mark Griffin www.it-ebooks.info Apple Watch for Developers: Advice & Techniques from Five Top Professionals Copyright © 2015 by Gary Riches, Ruben Martinez Jr., Jamie Maison, Matt Klosterman, Mark Griffin This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher's location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. ISBN-13 (pbk): 978-1-4842-1339-1 ISBN-13 (electronic): 978-1-4842-1338-4 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an edito- rial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director: Welmoed Spahr Lead Editor: Steve Weiss Technical Reviewer: Iliya Yordanov Editorial Board: Steve Anglin, Gary Cornell, Louise Corrigan, James T. DeWolf, Jonathan Gennick, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing, Matt Wade, Steve Weiss Coordinating Editor: Kevin Walter Project Editor: Troy Mott Copy Editor: Christina Rudloff Cover Designer: Crest Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales. Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com. For detailed information about how to locate your book’s source code, go to www.apress. com/source-code/. www.it-ebooks.info Contents at a Glance About the Authors ............................................................................................xiii About the Technical Reviewer ..........................................................................xv Acknowledgments ...........................................................................................xvii (cid:132)(cid:3)Chapter 1: An Apple Watch Introduction .....................................................19 (cid:132)(cid:3)Chapter 2: Examining the Stopwatch, Timer and Calendar ......................27 (cid:132)(cid:3)Chapter 3: Taming Complex Data for the Watch .........................................53 (cid:132)(cid:3)Chapter 4: Examining Home Remote and its Components .....................123 (cid:132)(cid:3)Chapter 5: Developing Notation – Audio to Musical Score .....................163 (cid:132)(cid:3)Chapter 6: Building the Infinitweet Application ........................................177 (cid:132)(cid:3)Chapter 7: Developing Apple Watch Cross-Platform Apps .....................207 Index .................................................................................................................239 v www.it-ebooks.info Contents About the Authors .......................................................................................xiii About the Technical Reviewer .....................................................................xv Acknowledgments ......................................................................................xvii (cid:132)(cid:3)Chapter 1: An Apple Watch Introduction .....................................................19 Anatomy of a WatchKit App .............................................................................20 The Interface Controller ................................................................................................20 Glance Interfaces ..........................................................................................................21 Notification Interfaces ...................................................................................................22 Interface Navigation ........................................................................................23 Context Menus ................................................................................................25 Summary .........................................................................................................25 (cid:132)(cid:3)Chapter 2: Examining the Stopwatch, Timer and Calendar ......................27 Stopwatch ........................................................................................................27 Creating the User Interface ...........................................................................................28 Outlets and Actions .......................................................................................................29 Triggering Timing ..........................................................................................................29 Adding the Lap Functionality .........................................................................................31 Timer ...............................................................................................................33 Creating the User Interface ...........................................................................................33 vii www.it-ebooks.info viii Contents Outlets and Actions .......................................................................................................34 Initializing the Application ..............................................................................................35 Handling Text Input with WatchKit .................................................................................36 Start and Reset ............................................................................................................37 Creating our Timer Method ...........................................................................................38 Calendar ..........................................................................................................40 Introduction to iCloud ....................................................................................................40 Creating Calendars and Events in iOS Using EventKit and iCloud ...............................43 Creating an Apple Watch Calendar Application ............................................................45 Summary .........................................................................................................51 (cid:132)(cid:3)Chapter 3: Taming Complex Data for the Watch .........................................53 Background .....................................................................................................54 Find Your User’s Story ....................................................................................56 Maintain Simplicity Through Relevancy ...........................................................77 Increase Recognition Through Repetition .....................................................108 Use Notifications as Punctuation ...................................................................120 Looking Forward: Complications in watchOS 2 ...........................................120 (cid:132)(cid:3)Chapter 4: Examining Home Remote and its Components .....................123 The WatchKit Extension ................................................................................124 The User Interface.........................................................................................125 Populating the Table ......................................................................................127 Handling the Table’s Input ...........................................................................................127 Sharing Data Between Extension and App ...................................................128 App Groups .................................................................................................................129 iOS .............................................................................................................................129 WatchKit ......................................................................................................................130 www.it-ebooks.info Contents ix Glances and Extension Communication .......................................................132 The Home Remote Glance ............................................................................132 The Glance ....................................................................................................133 Handoff ..........................................................................................................135 Handoff Interactions ....................................................................................................136 The Handoff Code .......................................................................................................136 Modal Interface Controllers .........................................................................................137 Navigation Types Available ............................................................................139 Home Remote Navigation .............................................................................140 Hierarchy and Page based Navigation ..........................................................140 Page based Navigation ...............................................................................................143 Hierarchical Navigation ...............................................................................................144 Force Touch Menus .......................................................................................146 The Design of the Menu Items ....................................................................................147 Apple Watch Settings ....................................................................................149 Home Remote and Voice Recognition ..........................................................151 About Voice Dictation ....................................................................................153 Adding Voice Recognition to the Table ..........................................................153 Submitting Your App for Review ....................................................................157 App Identifiers .............................................................................................................158 Version Numbers ........................................................................................................158 App Name and Settings Name ...................................................................................158 Assets Required for Submission ...................................................................159 Screen Shots ..............................................................................................................159 The Submission Process ...............................................................................160 Summary .......................................................................................................162 www.it-ebooks.info x Contents (cid:132)(cid:3)Chapter 5: Developing Notation – Audio to Musical Score .....................163 User Interface on the Apple Watch ...............................................................164 Branding Within Apple Watch Applications ...................................................166 Design Considerations ................................................................................................167 Working with App Groups ..............................................................................168 What are App Groups? ...............................................................................................168 Setting Up App Groups in Your Project .......................................................................168 Using the Apple Watch Microphone in watchOS 2 ......................................170 Swift ............................................................................................................................171 Objective-C .................................................................................................................171 Translating Audio Data into Visual Information ..............................................172 Importing and Declaring Images .................................................................................172 Updating Our Image ....................................................................................................175 Summary .......................................................................................................176 (cid:132)(cid:3)Chapter 6: Building the Infinitweet Application ........................................177 Introducing Infinitweet ...................................................................................177 Environment-Driven Feature Sets .................................................................179 Infinitweet for iOS ........................................................................................................179 Infinitweet for Apple Watch .........................................................................................180 So Where Does the Magic Happen? ..........................................................................181 Building Infinitweet .......................................................................................182 Getting Started ............................................................................................................182 Creating the Infinitweet User Interface ........................................................................184 Communicating Between Storyboard and Code .........................................................186 Capturing User Voice Input .........................................................................................188 Navigating Between WKInterfaceControllers ..............................................................189 Working with Social and Account Frameworks ...........................................................190 Prompting the User With Options................................................................................193 www.it-ebooks.info Contents xi The Infinitweet Algorithm.............................................................................................197 Providing User Feedback ............................................................................................201 Finishing Touches .......................................................................................................204 Additional Notes ..........................................................................................................205 (cid:132)(cid:3)Chapter 7: Developing Apple Watch Cross-Platform Apps .....................207 The FAIRFX Watch Application .....................................................................208 Building Watch Applications as a Cross-Platform Developer ........................209 Building Our Main Application with Cordova .................................................209 Bridging the Gap ...........................................................................................214 Getting a WatchKit App Up and Running ......................................................224 Linking the Applications Together..................................................................232 Common Pitfalls ............................................................................................234 Different Version Numbers ..........................................................................................234 Differing Deployment Targets ......................................................................................234 Downgrading the Deployment Target ..........................................................................235 Building Fine but Rejected at App Store .....................................................................235 Additional Features........................................................................................235 Android Wear ..............................................................................................................236 WatchKit for watchOS 2 ............................................................................................237 (cid:132)(cid:3)Index .............................................................................................................239 www.it-ebooks.info