Program the Internet of Things with Swift for iOS(Apress,2015)

所需积分/C币:10 2016-02-03 23:36:07 13.7MB PDF
20
收藏 收藏
举报

Program the Internet of Things with Swift and iOS is a detailed tutorial that will teach you how to build apps using Apple’s native APIs for the Internet of Things, including the Apple Watch, HomeKit, and Apple Pay. This is the second book by Ahmed Bakir (author of Beginning iOS Media App Developmen
Program the Internet of Things with Swift for iOS Copyright o 2016 by Ahmed Bakir, Gheorghe Chesler, and Manny de la Torriente 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 known or hereafter developed Exempted from this legal reservation are brief excerpts in connection wit ow storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology 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 Rights Link at the Copyright Clearance Center Violations are liable to prosecution under the respective Copyright Law. ISBN13(pbk):978-1-4842-1195-3 ISBN-13( electronic:978-1-4842-1194-6 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 editorial 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: michelle lowman Technical reviewer charles cruz Editorial Board: Steve Anglin, Louise Corrigan, Jonathan Gennick, Robert Hutchinson Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing Coordinating Editor: Mark Powers Copy Editor: Lori Jacobs Compositor: SPi Global Indexer: SPi global Artist: SPi Global Cover Designer: Anna Ishchenko 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 orvisitwww.springeronline.comApressMediaLlcisaCaliforniaLlcandthesolemember(owner)isSpringer Science+ Business Media Finance Inc(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation Forinformationontranslationspleasee-mailrights@apress.com,orvisitwww.apress.cor 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-eBookLicensingwebpageatwww.apress.com/bulk-sales Any source code or other supplementary materials referenced by the author in this text is available to readers atwww.apress.com/9781484211953.Fordetailedinformationabouthowtolocateyourbookssourcecodego towww.apress.com/source-code/.ReaderscanalsoaccesssourcecodeatSpringerlinkinthesUpplementary Material section for each chapter www.allitebooks.com Contents at a Glance About the authors ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ About the technical reviewer mxvif Introduction XIX Chapter 1: Building Your First Internet of Things app a ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Chapter 2: Getting Started with Swift. ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 33 Chapter 3: Accessing Health Information Using Healthkit 59 Chapter 4: Using Core Motion to Save Motion Data.maa g99 Chapter 5: Integrating Third-Party Fitness Trackers and Data Using the Fitbit APl ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 119 Chapter 6: Building Your First watchOS App 169 Chapter 7: Building an Interactive watchS App BoRnmann 201 Chapter 8: Building a Stand-Alone watchS App ammmmmaanmmmamnn 225 Chapter 9: Connecting to a bluetooth le device 247 Chapter 10: Building Location Awareness with iBeacons Ra RBaRRREaIIm 295 Chapter 11: Home Automation Using Homekit amamammanaamaEaaRnamanmai 343 i www.allitebooks.com Contents at a glance Chapter 12: Building an App That interacts with a raspberry pi 397 Chapter 13: Using Keychain Services to Secure Data ammmmamnmannn 427 Chapter 14: Using Touch ID for Local Authentication aat 443 Chapter 15: Using Apple Pay to Accept Payments. 457 Index 485 www.allitebooks.com Contents About the authors ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ About the technical reviewer mmm xvii Introduction XIX Chapter 1: Building Your First Internet of Things app a ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Ahmed bakir Setting up the project 2 Building the User Interface Creating the Table view controller. Creating the Map view Controller................................18 Requesting Location Permission DDDDDDDDBBDDDDDDDDBDBDDBBDBDDDDDDDBDBDBDBDB 22 Accessing the User's location 26 Displaying the User's location Populating the Table view Populating the Map 面日日国日日日面日日日面日自日日面日日面日日日面日日日面日日目面面日重目面面日面日面日面日面日面日面日面日日面日日面面日日面面日面日日面日面日面日日面日 Summary 32 www.allitebooks.com Contents Chapter 2: Getting Started with Swift. 33 Ahmed bakir 33 Why Use Swift?… 34 Basic Swift Syntax. Calling Methods (hello World) .. 35 Defining variables 36 Compound data Types…,,.,.,.,.,.,.,.,.,.,.,.,., 37 Conditional Logic 38 Enumerated Types Loops 40 Object-Oriented Programming in Swift …41 Building a Class Protocols 42 Method Signatures 43 Accessing Properties and methods. Instantiating objects Strings 46 Formatting Strings Collections …47 Casting. ...................................................................................................50 Swift- Specific Language Features 50 Optionals 50 Try-Catch Blocks 52 Mixing objective-C and Swift in Projects 54 Calling Swift from objective-C….…,… S umma 57 Chapter 3: Accessing Health Information Using Healthkit nmmmmammmamam 59 Ahmed bakir 59 ntroduction 59 www.allitebooks.com Contents Getting Started .611 Setting Up the User Interface Setting Up the project for HealthKit ,79 Prompting the User for HealthKit Permission Retrieving Data from Healthkit 日日面面日日面日面日自日面面日日面日面面日日面面日日面日面面日面日自日面面日正日面日面面日面面日自日面面日日面日面面日面日自日面面日面日面日面面 88 Displaying Results in a Table view …92 Fetching Background Updates Summary 97 Chapter 4: Using Core Motion to Save Motion Data maar ■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■ 99 Ahmed bakir 99 Introduction 99 Using Core Motion to Access Motion Hardware 100 Requesting User Permission for Motion Activity. Querying for Step count 103 Detecting Live Updates to Step Count 106 Detecting Activity Type 108 Saving data to healthkit …110 Summary 117 Chapter 5: Integrating Third-Party Fitness Trackers and Data Using the Fitbit APl ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 119 Gheorghe chesler… 119 Introduction to the fitbit apl 119 The restful Apl 日面重面面日面日日面日面日面重面面日面日日日面面日日日面日日面日面面日面日日面面日面面日重面 Fitbit restful aPI Implementation Details 122 Setting Up a Local Playground with Apache 123 The oauth 1, oa authentication model 125 The Fitbit OAuth Implementation Fitbit apl call rate limits 127 Making async calls 128 Using callbacks as Parameters 128 www.allitebooks.com Contents Setting up a Fitbit-compatible ios project ,130 Theviewcontrollerwwwwwwwww.130 The logger library...e....e.n 133 Setting up a Basic Set of crypto Functions 133 The APl Client Library 137 The OAuth Library. ..........................................151 Testing what We have so Far 157 Making reguests to the Fitbit APl …….159 Retrieving the User profile.ee.neece..oe 161 Retrieving and Setting Data in the aPl 163 OAuth versions: Working in both worlds.. …167 S umma 168 Chapter 6: Building Your First watchOS App m Bm amman. 169 Ahmed bakir 169 Introduction 169 watchS Apps Vs iOS Apps 170 Setting Up Your project. 172 Debugging your watchS App 176 Adding a Table to your watchS App 176 Defining the Table 181 Fetching Data from your i0sApp...,……,187 Building a Detail Page with a custom Layout 190 Presenting the detail Interface Controller Summary… 199 Chapter 7: Building an Interactive watchS App ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Ahmed baki 201 Introduction 201 Using Force Touch to Present Menus 202 Resetting the Location List 206 Presenting a Detail view Controller. Simulating force touch 209 www.allitebooks.com Contents Adding Buttons to an Interface Controller 210 Passing Information Between Interface Controllers. ing a delegate to pass Information on Dismissal 215 How to Add Notes Using Text Input 217 Sending Data Back to the Parent iOS App...............................219 Summary… …….223 Chapter 8: Building a Stand-Alone watchOS App nn 225 Ahmed Bakir. mm. 225 Using Core Location to Request current Location. Reverse Geocoding an Address. Using NSTimer to Create Reminders …233 Making Network Calls from Your watchOS App ……238 Handling a JSoN Response 243 Summary …245 Chapter 9: Connecting to a bluetooth le Device ■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■ 247 Manny de la Torriente …247 Introduction to the Apple bluetooth stack 247 Key Terms and concepts . …248 Core bluetooth objects 249 Building Your First Bluetooth LE Application 250 Backlog 251 Base application and home scene 251 Central role scene 面日自日面日日面B日面日面日日面日日面日日面面日日面日面日面面目面日面面日面面日面日面面日面面日面日日面面日面日日面面日面面日日面面日面面日面日面面日面面日面日面日面面 252 Peripheral Role Scene…… 253 Editable text…255 Setting Up the project ……256 Building the Interface ……256 Using a central manager nnnnnnnnnnnnnnnnnnnnnnnnnnI 264 www.allitebooks.com

...展开详情
试读 127P Program the Internet of Things with Swift for iOS(Apress,2015)
立即下载 身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
  • 至尊王者

关注 私信
上传资源赚钱or赚积分
最新推荐
Program the Internet of Things with Swift for iOS(Apress,2015) 10积分/C币 立即下载
1/127
Program the Internet of Things with Swift for iOS(Apress,2015)第1页
Program the Internet of Things with Swift for iOS(Apress,2015)第2页
Program the Internet of Things with Swift for iOS(Apress,2015)第3页
Program the Internet of Things with Swift for iOS(Apress,2015)第4页
Program the Internet of Things with Swift for iOS(Apress,2015)第5页
Program the Internet of Things with Swift for iOS(Apress,2015)第6页
Program the Internet of Things with Swift for iOS(Apress,2015)第7页
Program the Internet of Things with Swift for iOS(Apress,2015)第8页
Program the Internet of Things with Swift for iOS(Apress,2015)第9页
Program the Internet of Things with Swift for iOS(Apress,2015)第10页
Program the Internet of Things with Swift for iOS(Apress,2015)第11页
Program the Internet of Things with Swift for iOS(Apress,2015)第12页
Program the Internet of Things with Swift for iOS(Apress,2015)第13页
Program the Internet of Things with Swift for iOS(Apress,2015)第14页
Program the Internet of Things with Swift for iOS(Apress,2015)第15页
Program the Internet of Things with Swift for iOS(Apress,2015)第16页
Program the Internet of Things with Swift for iOS(Apress,2015)第17页
Program the Internet of Things with Swift for iOS(Apress,2015)第18页
Program the Internet of Things with Swift for iOS(Apress,2015)第19页
Program the Internet of Things with Swift for iOS(Apress,2015)第20页

试读结束, 可继续阅读

10积分/C币 立即下载