Skip to main content
main-content
Top

About this book

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 Development) and his team at devAtelier LLC, who have been involved in developing over 20 mobile projects.

Written like a code review, this book presents a detailed "how" and "why" for each topic, explaining Apple-specific design patterns as they come up and pulling lessons from other popular apps. To help you getting up and running quickly, each chapter is framed within a working project, allowing you to use the sample code directly in your apps.

The Internet of Things is not limited to Apple devices alone, so this book also explains how to interface with popular third-party hardware devices, such as the Fitbit and Raspberry Pi, and generic interfaces, like Restful API’s and HTTPS. The Internet of Things is waiting — be a part of it!

Table of Contents

Chapter 1. Building Your First Internet of Things App

To help introduce you to the style of this book, your first project will be a very simple application that demonstrates several of the steps you will take when building an Internet of Things application: creating a project, including hardware-specific frameworks, retrieving data, and displaying it. For your first project, you will create an application that logs the user’s location using his phone’s GPS chip and displays it on a map. This app could be used to help him find his car if he has the tendency to forget where it is (like a certain author). Figure 1-1 shows the mock-up, indicating the major user interface (UI) components and the flow of the application. The application you will create will follow the guideline set by this mock-up closely.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 2. Getting Started with Swift

As it is one of the newest programming languages on the market, one would be remiss to start a Swift book without offering the reader a brief introduction to the language. Readers who already feel comfortable with Swift can skip this chapter entirely or just reference the sections they are curious about.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 3. Accessing Health Information Using HealthKit

For the last few years, Apple has provided two core frameworks that have sped up the time to develop iOS health apps considerably: HealthKit and Core Motion. HealthKit provides a central repository for all apps to sync health data and Core Motion provides access to the iPhone’s accelerometer and pedometer, allowing you to retrieve limited health information about a user without external accessories.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 4. Using Core Motion to Save Motion Data

In the last chapter, you learned how to set up an application for HealthKit, Apple’s shared repository for health data, and query for specific health data types. In this chapter, you will learn how to use Core Motion to access live motion data from a user’s device, and how to save it back to HealthKit, where it will be accessible to all applications.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 5. Integrating Third-Party Fitness Trackers and Data Using the Fitbit API

One would be remiss to discuss health sensors without mentioning the most popular connected motion tracker on the market, the Fitbit. Through its web-based API (application programming interface), Fitbit allows developers to access activity logged from its hardware, as well as related health information from Fitbit’s ecosystem, including meals and weight. This chapter will teach developers how to connect to the API from within their apps, as well as how to retrieve information from it and log new activities.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 6. Building Your First watchOS App

In late 2014, Apple replied to the vocal concerns of many of its critics and consumers by introducing a completely new “product category” — the Apple Watch. This came as a surprise to (almost) everyone, why would the most profitable computer company in history enter the smart watch market, a “fad” that had yet to achieve a killer app? Similarly, how would they address people’s bias as to how watches should look and work (they’ve only been around for a few thousand years)? And what would they do to make it an app platform?
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 7. Building an Interactive watchOS App

In this chapter, you will learn how to make the CarFinder watchOS app even more powerful by adding interactive features. While an app that can let you view information from your iPhone is great, there is even more value in an app that allows you to create new data from your watch. The interactive features you will add to the CarFinder app in this chapter will demonstrate the following features of watchOS:
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 8. Building a Stand-Alone watchOS App

In this chapter, you will learn about one of the greatest attributes of watchOS 2: its capabilities that let you build an app that runs natively, even offline, without maintaining an active connection to your parent iOS app. So far, you have noticed that watchOS 2 apps share many design features with iOS apps, including interface controllers (view controllers), notifications, and delegation. With watchOS 1, you were limited to building “listener” apps, designed to respond to data manifests from a parent app; they were not intended to provide anything more than consumption. watchOS 2 bridges a huge gap because it allows you to build apps that not only are designed like iOS apps but also function like iOS apps.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 9. Connecting to a Bluetooth LE Device

Thanks to its open standards, Bluetooth Low-Energy (LE), also known as BLE,has established itself as a leader for hardware manufacturers looking to create connected accessories for iOS. This chapter introduces Core Bluetooth, Apple’s framework for Bluetooth-based communication, to send and receive messages from a Bluetooth LE device. Additionally, we will discuss Bluetooth best practices for battery life and a positive user experience.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 10. Building Location Awareness with iBeacons

This chapter introduces iBeacon technology and will show you how to use the Core Location framework to interact with beacons. You’ll learn how to establish a region around an object, determine when a region has been entered or exited, and estimate your proximity to a beacon. You’ll also learn how to configure your iOS device to act as an iBeacon transmitter.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 11. Home Automation Using HomeKit

Much like Apple sought to unify health data with HealthKit, HomeKit is Apple’s entry into home automation. Apple created a unified communications protocol—HomeKit Accessory Protocol— for connected home manufactures. HomeKit is a common set of APIs (application programming interfaces) for applications that provides integration between iOS devices and accessories that support the HomeKit Accessory Protocol.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 12. Building an App That Interacts with a Raspberry Pi

In this chapter, we will write an app that communicates with a Raspberry Pi device on the local Wi-Fi network that allows us to flip the lights on and off on a custom module with LEDs. This might not seem like a significant accomplishment, but keep in mind that just as you can flip on and off some LED lights, you can control any other connected devices in a similar fashion.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 13. Using Keychain Services to Secure Data

Although the iPhone boasts the lowest rate of security issues for a major computing platform, many developers only take advantage of a handful of these features. In this chapter, we will introduce Keychain Services, Apple’s security framework for encrypting notes, passwords, and SSL (Secure Socket Layer) certificates at the system level.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 14. Using Touch ID for Local Authentication

Ever-increasing rates of phone theft and identity fraud have pushed second-factor authentication from a desired feature to a necessity. Touch ID allows developers to use the iPhone’s built-in fingerprint sensor without any of the heavy lifting of pattern recognition or low-level encryption. In this chapter, readers will learn about the framework and how to add fingerprint identification to their apps.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente

Chapter 15. Using Apple Pay to Accept Payments

In the short time since its introduction, Apple Pay has driven Near-Field Communication (NFC) payments with unprecedented momentum. Apple now takes this a step further by allowing developers to use Apple Pay to accept payments for physical goods in their apps, a feature which has been successfully adopted by Uber and Starbucks. This chapter introduces readers to Apple Pay by demonstrating how to integrate the framework for in-app payments, as well as discussing traditional challenges in implementing payment systems.
Ahmed Bakir, Gheorghe Chesler, Manny de la Torriente
Additional information