Real-World Interaction

Some of the most important iOS apps are those that facilitate real-world interactions, with the user’s environment and with the user him- or herself.

Location, Motion, and Mapping

It used to be that you’d be crazy to go driving around an unfamiliar city without a map. Now we don’t think twice about visiting new places, since our iPhones can fetch maps or directions on demand (but please hand the iPhone to a passenger while you’re actually behind the wheel).

The Core Location framework is used for dealing with locations on the surface of the Earth. You can use it to fetch the latitude and longitude of the device’s current location, fetched from GPS (if equipped) or the known locations of available Wi-Fi networks. Core Location also offers geocoding, mapping locations to city/state/country information and vice versa. Apps that work with Apple’s iBeacons for interacting with short-range points of interest, like departments of a store, do so using Core Location’s CLBeacon type.

While Core Location tells you where you are, MapKit can tell you where you are going. With MapKit, an app can perform location-based searches for points of interest, or request driving or walking directions between two locations. MapKit also provides an MKMapView for showing maps as UIViews in your app.

On a much smaller scale, Core Motion uses the gyroscopes and compass in the device to sense motion and orientation. You can use this framework to find out when and how the phone is being moved around, which compass direction it’s facing, and even get pedometer data as the user walks around with the device.

HealthKit

In the last few years, and especially since the debut of Apple Watch, iOS has shown a keen interest in health-tracking data. To the third-party developer, this is available through the HealthKit framework. This framework allows apps to access data like step count, pulse, weight, and more, as entered manually by the user or as monitored by their Apple Watch, the M7 motion-sensor chip in the iPhone, or other compatible devices.

Health data is uniquely sensitive and must be handled with more care than, say, a user’s favorite podcasts or their lock screen picture. HealthKit apps require developers to provide an explicit privacy policy for how the health data will be used, and forbid a wide range of behaviors that fall outside of what can be addressed in code; for example, you cannot serve advertising based on the user’s health data. Full details are available in HealthKit’s docs.

Interacting with Other Devices

Finally, iOS devices can interact with many other kinds of devices, increasing the usefulness of both. HomeKit is Apple’s protocol for Internet-of-things products, such as smart appliances, security systems, and so on. The HomeKit framework in iOS lets you discover the devices in a home and the services they provide, and communicate with them.

For general-purpose wireless connectivity, including the vast number of third-party devices that use Bluetooth LE (“Low Energy”), iOS offers Core Bluetooth. This low-level framework allows your app to discover nearby LE devices and send requests to them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset