Event Handling Starting Point

Events are objects sent to an application to inform it of user actions. Events are generated whenever the user interacts with the user interface as well as when the user interacts with the accelerometer or uses a headset or other external accessory. There are also events generated when the location of the device changes.

image: Art/event-handling-sp.jpg

Contents:

Get Up and Running

Read The Event-Handling System in App Programming Guide for iOS for an overview of event handling and read Event Handling Guide for iOS for specific tasks. Event Handling Guide for iOS describes how to handle user events including multitouch events, motion events—from device accelerometers—and events for controlling multimedia. At a minimum, every application should respond to orientation changes.

Become Proficient

Start with UIKit Framework Reference to learn about the event handling classes in the UIKit framework. The framework includes classes for working with data, such as acceleration, device, screen, event, responder, and touch data.

Access Accelerometer Events

An accelerometer measures changes in velocity along a given linear path. iOS devices contain three accelerometers, one along each of the primary axes of the device. Read Motion Events in Event Handling Guide for iOS for an overview and refer to Core Motion Framework Reference for details on the accelerometer and gyroscope classes.

See the sample code project BubbleLevel, which uses accelerometer data to create a visual bubble level and inclinometer. This project provides an example of how to detect device orientation.

Determine the Device Location

iOS devices contain hardware that can determine the device’s current location, triangulating a position fix from available signal information. To learn how to determine the current latitude and longitude of a device, start by reading Location and Maps Programming Guide and refer to Core Location Framework Reference for details on location classes.