<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreHaptics",
  "identifier" : "/documentation/CoreHaptics/CHHapticEngine",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Haptics"
    ],
    "preciseIdentifier" : "c:objc(cs)CHHapticEngine"
  },
  "title" : "CHHapticEngine"
}
-->

# CHHapticEngine

An object that represents the connection to the haptic server.

```
class CHHapticEngine
```

## 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.

![A dictionary defines a pattern, from which the haptic engine creates a pattern player for playing the haptic.](images/com.apple.corehaptics/media-3242669@2x.png)

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:)`](/documentation/CoreHaptics/CHHapticEngine/start(completionHandler:)) for an asynchronous start, or [`start()`](/documentation/CoreHaptics/CHHapticEngine/start()) to start the engine synchronously (immediately).
3. Stop the engine by calling [`stop(completionHandler:)`](/documentation/CoreHaptics/CHHapticEngine/stop(completionHandler:)) when your app finishes haptic playback.

```swift
do {
    // 1. Create a haptic engine instance.
    hapticEngine = try CHHapticEngine()

    // 2. Start the haptic engine.
    try hapticEngine.start()
} catch let error {
    print("Engine Error: \(error)")
}

// 3. Stop the engine.
hapticEngine.stop(completionHandler: { (_) -> Void in
    // Insert code to call after engine stops.
})
```

Although it’s possible to create content—[`CHHapticPattern`](/documentation/CoreHaptics/CHHapticPattern) instances—independent of a CHHapticEngine, your app must use an engine to play that content.

## Topics

### Initializing a Haptic Engine

[`init()`](/documentation/CoreHaptics/CHHapticEngine/init())

Creates an instance of the haptic engine.

[`init(audioSession:)`](/documentation/CoreHaptics/CHHapticEngine/init(audioSession:))

Creates a haptic engine from an audio session.

### Starting and Stopping the Haptic Engine

[`start()`](/documentation/CoreHaptics/CHHapticEngine/start())

Synchronously starts the haptic engine.

[`start(completionHandler:)`](/documentation/CoreHaptics/CHHapticEngine/start(completionHandler:))

Asynchronously starts the haptic engine.

[`stop(completionHandler:)`](/documentation/CoreHaptics/CHHapticEngine/stop(completionHandler:))

Asynchronously stops the haptic engine and executes the completion handler once the engine has stopped.

[`CHHapticEngine.CompletionHandler`](/documentation/CoreHaptics/CHHapticEngine/CompletionHandler)

A typealias for a completion handler that the engine calls after starting or stopping.

### Creating Haptic Pattern Players

Factory methods for creating player objects for haptic playback.

[`makePlayer(with:)`](/documentation/CoreHaptics/CHHapticEngine/makePlayer(with:))

Creates a standard haptic pattern player from a haptic pattern.

[`makeAdvancedPlayer(with:)`](/documentation/CoreHaptics/CHHapticEngine/makeAdvancedPlayer(with:))

Creates an advanced haptic pattern player from a haptic pattern.

### Modifying Playback Properties

[`playsAudioOnly`](/documentation/CoreHaptics/CHHapticEngine/playsAudioOnly)

A Boolean value that indicates whether the engine ignores haptic events and plays audio events only.

[`playsHapticsOnly`](/documentation/CoreHaptics/CHHapticEngine/playsHapticsOnly)

A Boolean value that indicates whether the engine ignores audio events.

[`isMutedForAudio`](/documentation/CoreHaptics/CHHapticEngine/isMutedForAudio)

A Boolean value that indicates whether the engine mutes audio.

[`isMutedForHaptics`](/documentation/CoreHaptics/CHHapticEngine/isMutedForHaptics)

A Boolean value that indicates whether the engine mutes haptics.

### Playing a Pattern

[`playPattern(from:)`](/documentation/CoreHaptics/CHHapticEngine/playPattern(from:)-6m9m5)

Plays a pattern that’s defined in a file at the specified URL.

[`playPattern(from:)`](/documentation/CoreHaptics/CHHapticEngine/playPattern(from:)-7u8se)

Plays a pattern from the specified data.

### Registering Audio Resources

[`registerAudioResource(_:options:)`](/documentation/CoreHaptics/CHHapticEngine/registerAudioResource(_:options:))

Registers an external audio to use as a custom waveform.

[`unregisterAudioResource(_:)`](/documentation/CoreHaptics/CHHapticEngine/unregisterAudioResource(_:))

Unregisters an external audio file that you previously registered with the engine.

[`CHHapticAudioResourceID`](/documentation/CoreHaptics/CHHapticAudioResourceID)

A type that identifies a custom audio resource.

### Monitoring Finished Playback

[`notifyWhenPlayersFinished(finishedHandler:)`](/documentation/CoreHaptics/CHHapticEngine/notifyWhenPlayersFinished(finishedHandler:))

Notifies you when all haptic pattern players have finished playing their haptic patterns.

[`CHHapticEngine.FinishedHandler`](/documentation/CoreHaptics/CHHapticEngine/FinishedHandler)

A type alias for a completion handler to execute after finishing haptic playback.

[`CHHapticEngine.FinishedAction`](/documentation/CoreHaptics/CHHapticEngine/FinishedAction)

Possible actions to take after the haptic engine finishes execution.

### Handling Haptic Engine Resets

[`resetHandler`](/documentation/CoreHaptics/CHHapticEngine/resetHandler-swift.property)

A block that the haptic engine calls after recovering from a haptic server error.

[`CHHapticEngine.ResetHandler`](/documentation/CoreHaptics/CHHapticEngine/ResetHandler-swift.typealias)

A typealias for the block that the haptic engine calls after being reset.

### Handling Haptic Engine Stoppages

[`stoppedHandler`](/documentation/CoreHaptics/CHHapticEngine/stoppedHandler-swift.property)

A closure the haptic engine calls when it stops due to external causes.

[`CHHapticEngine.StoppedHandler`](/documentation/CoreHaptics/CHHapticEngine/StoppedHandler-swift.typealias)

A typealias for the block that the haptic engine calls after it stops due to an external cause.

[`CHHapticEngine.StoppedReason`](/documentation/CoreHaptics/CHHapticEngine/StoppedReason)

The enumeration of reasons the haptic engine stopped running.

### Getting the Current Media Time

[`currentTime`](/documentation/CoreHaptics/CHHapticEngine/currentTime)

The absolute time, in seconds, to use for scheduling haptic and audio events.

[`CHHapticTimeImmediate`](/documentation/CoreHaptics/CHHapticTimeImmediate)

A time constant used to schedule a command immediately.

### Querying System Capabilities

[`capabilitiesForHardware()`](/documentation/CoreHaptics/CHHapticEngine/capabilitiesForHardware())

Returns a device capability object that describes the device’s haptic support and limitations.

[`CHHapticDeviceCapability`](/documentation/CoreHaptics/CHHapticDeviceCapability)

A protocol that defines haptics and audio capabilities of a device.

[`CHHapticParameterAttributes`](/documentation/CoreHaptics/CHHapticParameterAttributes)

A protocol for providing default, mininum, and maximum values of a parameter.

[`attributes(forDynamicParameter:)`](/documentation/CoreHaptics/CHHapticDeviceCapability/attributes(forDynamicParameter:))

Requests the haptic device’s attributes for a dynamic parameter.

### Managing Power

[`isAutoShutdownEnabled`](/documentation/CoreHaptics/CHHapticEngine/isAutoShutdownEnabled)

A Boolean value that indicates whether the haptic engine starts and stops automatically on request from one of its pattern players, or when idle.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)