Skip to content

fotiDim/UniHaptic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UniHaptic: Unified API for Haptic Feedback & Vibration

iOS 7+ Swift 5.1 Swift Package Manager License: MIT

Unified API for CHHapticEngine /UIFeedbackGenerator haptic feedback and AudioToolbox vibration. Supports from iOS 13 all the way down to iOS 7.

Installation

Use Swift Package Manager though Xcode 11. Simply go to File -> Swift Packages -> Add Package Dependency... and paste the URL of this repo.

Usage

The API is meant to be as simple as possible. First do your import:

import UniHaptic

and then simply call it:

UniHaptic().vibrate()

You can have more control by initializing the UniHaptic class with a specific style of vibration like this (UniHaptic(style: .impact). The available options are:

  • selection
  • impact
  • notification
  • custom

If you don't provide any option the default will be .selection.

You also have the option to provice specific intensity and sharpness to vibrate:

UniHaptic().vibrate(intensity: 0.7, sharpness: 0.7)

Sharpness is only used if UniHaptic was initialized with .custom style.

Minimize Latency

The above example while being simple it does not provide the lowest possible latency. To get minimal latency initialize Unihaptic in a separate call and store its instance:

class MyClass {
    var unihaptic = UniHaptic()

    func myFunction() {
        unihaptic.vibrate()
    }
}

Then when you call vibrate() the latency will be the lowest possible as the Haptic Engine is prepared. For more information read here.

Project Status

The project is in its early steps. It is perfectly usable as it is but the API might change.