HapticsKit provides developers for Apple platforms with the ability to quickly add haptic feedback to their apps.
HapticsKit is available on all Apple platforms but is only functional on devices which have support for haptic feedback (iPhone & Apple Watch).
- iOS/iPadOS 17.0+
- macOS 14.0+
- tvOS 17.0+
- visionOS 1.0+
- watchOS 10.0+
- Xcode 15.0+
HapticsKit can be added to your app via Swift Package Manager in Xcode. Add to your project like so:
dependencies: [
.package(url: "https://github.com/adamfootdev/HapticsKit.git", from: "2.0.9")
]
To start using the framework, you'll need to import it first:
import HapticsKit
This is a struct containing all of the relevant details required to configure HapticsKit. It can be created like so:
let configuration = HapticsKitConfiguration(
userDefaults: UserDefaults.standard,
storageKey: "hapticFeedback"
)
Both attributes are optional and default values can be used instead.
When launching your app, configure HapticsKit like so:
let haptics = HapticsKit.configure(with: configuration)
If you do not configure HapticsKit at launch, a default configuration will be used instead. You can then access HapticsKit in the future by referencing the created version as above or:
HapticsKit.shared
On iOS, the following methods can be called to perform haptic feedback:
HapticsKit.shared.performNotification(.success) // .success, .warning, .error
HapticsKit.shared.performImpact(.medium, at: 1.0) // .light, .medium, .heavy, .soft, .rigid; 0...1
HapticsKit.shared.performSelection()
On watchOS, the following method can be called to perform haptic feedback:
HapticsKit.shared.perform(.click) // .notification, .directionUp, .directionDown, .success, .failure, .retry, .start, .stop, .click
When performing haptic feedback, HapticsKit will check whether the user has haptic feedback enabled. The UserDefaults store and key can be configured as part of the configuration. Checking if haptic feedback is enabled can be done like so:
let enabled = HapticsKit.shared.hapticFeedbackEnabled
This value can be added to a SwiftUI Toggle as a binding. To check whether a device supports haptic feedback, you can use the following:
let deviceSupportsHapticFeedback = HapticsKit.hapticFeedbackSupported
You can use my app Haptics to test out the different haptic feedback combinations.
Add an about screen to your app.
Add a features list screen to your app.
Add a help screen to your app.