Compose and play haptic patterns to customize your iOS app's haptic feedback.
- iOS 13.0+Beta
- Mac Catalyst 13.0+Beta
Core Haptics lets you add customized haptic and audio feedback to your app. Use haptics to engage users physically, with tactile and audio feedback that gets attention and reinforces actions. Some system-provided interface elements—like pickers, switches, and sliders—automatically provide haptic feedback as users interact with them. With Core Haptics, you extend this functionality by composing and combining haptics beyond the default patterns.
Your app can play custom haptic patterns crafted from basic building blocks called haptic events (
CHHaptic). Events can be transient, like the feedback you get from toggling a switch, or continuous, like the vibration or sound from a ringtone. You can use transient and continuous patterns independently, or build your pattern from precise combinations of the two. Another type of haptic event allows you to play customized audio content as part of your pattern.
Haptic Intensity and Sharpness
Regardless of the building block you choose to generate a custom haptic, you can control its intensity and sharpness. Intensity varies the haptic’s amplitude or strength. Sharpness lets you determine the character of the haptic experience. For example, you can use sharpness values to convey an experience that's crisp, precise, and mechanical, or one that's soft, rounded, and organic.
To add haptics to your app, you create an instance of
CHHaptic, load a pattern, and use the engine to create a player to play that pattern. You create a pattern in one of three ways:
Dictionaries. Each entry in the dictionary defines a single characteristic of the haptic, like its intensity, start time, or duration. See Playing a Single-Tap Haptic Pattern to learn more about creating a dictionary inline.
Arrays of events and parameters. The
CHHapticclass represents a haptic event as an object in code. The key-value pairs in a dictionary correspond to the properties and parameters associated with a
CHHaptic. Haptic event objects are just another representation of the haptics dictionary.
AHAP files. This JSON-compliant file format specifies a haptic pattern through key-value pairs, analogous to a dictionary literal, except in a text file. Add this file to your Xcode project bundle.
You can produce the same kind of content with all forms of pattern creation.