Contents

CHHapticEngine

An object that represents the connection to the haptic server.

Declaration

class CHHapticEngine

Mentioned in

Overview

If you want your app to play custom haptics, you need to create a haptic engine. The haptic engine establishes the connection between your app and the underlying device hardware. Even though you can define a haptic pattern without an engine, you need the engine to play that pattern.

[Image]

Even though your app makes a request through the haptic engine, the operating system could still override the request with system services, like haptics from system notifications.

Prepare Your App To Play Haptics

To prepare your app to play haptics, follow these steps, as demonstrated in the code below:

  1. Create a haptic engine instance. Maintain a strong reference to it so it doesn’t go out of scope while the haptic is playing.

  2. Call the haptic engine’s start(completionHandler:) for an asynchronous start, or start() to start the engine synchronously (immediately).

  3. Stop the engine by calling stop(completionHandler:) when your app finishes haptic playback.

Although it’s possible to create content—CHHapticPattern instances—independent of a CHHapticEngine, your app must use an engine to play that content.

Topics

Initializing a Haptic Engine

Starting and Stopping the Haptic Engine

Creating Haptic Pattern Players

Modifying Playback Properties

Playing a Pattern

Registering Audio Resources

Monitoring Finished Playback

Handling Haptic Engine Resets

Handling Haptic Engine Stoppages

Getting the Current Media Time

Querying System Capabilities

Managing Power

Initializers

Instance Properties

See Also

Essentials