Skip to content

adamfootdev/HapticsKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HapticsKit

Platform

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

  1. Requirements
  2. Integration
  3. Usage
  4. Testing Haptic Feedback
  5. Other Packages

Requirements

  • iOS/iPadOS 17.0+
  • macOS 14.0+
  • tvOS 17.0+
  • visionOS 1.0+
  • watchOS 10.0+
  • Xcode 15.0+

Integration

Swift Package Manager

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")
]

Usage

To start using the framework, you'll need to import it first:

import HapticsKit

HapticsKitConfiguration

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.

HapticsKit

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

Testing Haptic Feedback

You can use my app Haptics to test out the different haptic feedback combinations.

Other Packages

Add an about screen to your app.

Add a features list screen to your app.

Add a help screen to your app.

About

Add haptic feedback to your app in just a few lines of code.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages