Library / Outcomes & notifications
Payment complete (custom double-pulse)
An Apple Pay-style confirmation: a soft pre-tap followed by a strong full-body pulse.
import CoreHaptics
func playPaymentSuccess(engine: CHHapticEngine) throws {
let ready = CHHapticEvent(
eventType: .hapticTransient,
parameters: [
CHHapticEventParameter(parameterID: .hapticIntensity, value: 0.4),
CHHapticEventParameter(parameterID: .hapticSharpness, value: 0.7),
],
relativeTime: 0)
// A short continuous event reads as a "thump" rather than a tick
let thump = CHHapticEvent(
eventType: .hapticContinuous,
parameters: [
CHHapticEventParameter(parameterID: .hapticIntensity, value: 1.0),
CHHapticEventParameter(parameterID: .hapticSharpness, value: 0.3),
],
relativeTime: 0.25,
duration: 0.13)
let pattern = try CHHapticPattern(events: [ready, thump], parameters: [])
let player = try engine.makePlayer(with: pattern)
try engine.start()
try player.start(atTime: CHHapticTimeImmediate)
}
// Fallback for devices without Core Haptics:
// UINotificationFeedbackGenerator().notificationOccurred(.success)