Easy Haptic Feedback Generator 📳

Overview

Haptica

Build Status Carthage Compatible Language Version License Platform

Haptica is an easy haptic feedback generator.

$ pod try Haptica

Requirements

  • iOS 9.0+
  • Xcode 8.0+
  • Swift 5 (Haptica 3.x), Swift 4 (Haptica 2.x), Swift 3 (Haptica 1.x)

Haptic Feedback Requirements:

  • A device with a supported Taptic Engine.
  • App is running in the foreground.
  • System Haptics setting is enabled.

Usage

Generate using a haptic feedback type.

Haptic.impact(.light).generate()

Feedback Types

  • Impact: (UIImpactFeedbackStyle) - Use impact feedback generators to indicate that an impact has occurred. For example, you might trigger impact feedback when a user interface object collides with something or snaps into place.
    • light
    • medium
    • heavy
  • Notification: (UINotificationFeedbackType) - Use notification feedback to communicate that a task or action has succeeded, failed, or produced a warning of some kind.
    • success
    • warning
    • error
  • Selection - Use selection feedback to communicate movement through a series of discrete values.

Vibration Patterns

Play a custom vibration pattern:

Haptic.play("..oO-Oo..", delay: 0.1)

Use pattern symbols to represent custom vibrations.

  • O - heavy impact
  • o - medium impact
  • . - light impact
  • - - wait 0.1 second

Or play a symphony of notes:

Haptic.play([.haptic(.impact(.light)), .haptic(.impact(.heavy)), .wait(0.1), .haptic(.impact(.heavy)), .haptic(.impact(.light))])

UIButton Extension

To enable haptic feedback on buttons, set these properties:

  • isHaptic - enables haptic feedback
  • hapticType - haptic feedback type
button.isHaptic = true
button.hapticType = .impact(.light)

or use these functions to set the haptic feedback type for control events:

  • addHaptic() - add haptic feedback for control events
  • removeHaptic() - remove haptic feedback for control events
button.addHaptic(.selection, forControlEvents: .touchDown)
button.removeHaptic(forControlEvents: .touchDown)

Functions/Properties

var isHaptic: Bool // enables haptic feedback
var hapticType: Haptic? // haptic feedback type
var hapticControlEvents: UIControl.Event? // haptic feedback control events
func addHaptic(_ haptic: Haptic, forControlEvents events: UIControl.Event) {} // add haptic feedback for control events
func removeHaptic(forControlEvents events: UIControl.Event) {} // remove haptic feedback for control events

Sound Effects

Add sound effects to Haptica using Peep.

Peep.play(sound: KeyPress.tap)

Installation

CocoaPods

To install with CocoaPods, simply add this in your Podfile:

use_frameworks!
pod "Haptica"

Carthage

To install with Carthage, simply add this in your Cartfile:

github "efremidze/Haptica"

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Mentions

License

Haptica is available under the MIT license. See the LICENSE file for more info.

Comments
  • Public API improvements

    Public API improvements

    There is no real issue and this topic is more of an observation type.

    Q.1: I used Haptica as:

    button.isHaptic = true // required call.
    button.hapticType = .impact(.light) // optional, but has to be set.
    button.hapticControlEvents = .touchUpInside // optional, default is .touchDown as per implementation.
    

    My initialization logic has a flaw since button.isHaptic = true immediately triggers a call to addTarget() with .touchDown as default value (if hapticControlEvents is not set). Hence hapticControlEvents should be initialized before button.isHaptic = true invocation to make any effect.

    Would this make sense to refactor and introduce methods like these:

    func addHaptic(_ haptic: Haptic, forControlEvents events: UIControl.Event = .touchUpInside)
    func removeHaptic()
    

    to enable 1 line setup? Methods naming strategy 'addHaptic', 'removeHaptic' stolen from 'addTarget', 'removeTarget'.

    Q.2: Does it make sense to implement Hapticable for UIControl rather than UIButton? (since addTarget and removeTargets methods implemented in UIControl). This would enable Haptics for elements like UISwitch.

    opened by genkernel 3
  • Updated support for SPM

    Updated support for SPM

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by rcasula 2
  • Updated to Swift 4.2 Xcode 10

    Updated to Swift 4.2 Xcode 10

    Checklist

    • [ ] I've tested my changes.
    • [ ] I've read the Contribution Guidelines.
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by IgorMuzyka 2
  • Rigid and Soft - would you consider adding them to the vibration pattern symbols? Thanks!

    Rigid and Soft - would you consider adding them to the vibration pattern symbols? Thanks!

    opened by chrisperfer 1
  • iOS 13 feedback types support

    iOS 13 feedback types support

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Motivation and Context

    Two new types of feedback intensity in iOS13 which are not handled or mapped in Haptica.

    Description

    Added soft and rigid types of feedback and updated the example app.

    opened by kirillivonin 1
  • Fixed SwiftPM manifest

    Fixed SwiftPM manifest

    Checklist

    • [ ] I've tested my changes.
    • [ ] I've read the Contribution Guidelines.
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by rafaelfrancisco-dev 1
  • Random crashes, exception UIFeedbackHapticOnlyEngine _deactivate

    Random crashes, exception UIFeedbackHapticOnlyEngine _deactivate

    I am using Haptica in my app I recently release a new version of my app on 16 July after that repeating crashes are reported on Xcode organiser. Below are the exception details:-

    ERROR: -[_UIFeedbackHapticOnlyEngine _deactivate] called more times than the feedback engine was activated

    Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x1f7bc927c __exceptionPreprocess 1 libobjc.A.dylib 0x1f6da39f8 objc_exception_throw 2 CoreFoundation 0x1f7ae2988 +[_CFXNotificationTokenRegistration keyCallbacks] 3 Foundation 0x1f85a6188 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 4 UIKitCore 0x224055628 -[_UIFeedbackEngine _deactivate] 5 UIKitCore 0x22403e58c -[UIFeedbackGenerator __deactivateWithStyle:] 6 libdispatch.dylib 0x1f7608a38 _dispatch_call_block_and_release 7 libdispatch.dylib 0x1f76097d4 _dispatch_client_callout 8 libdispatch.dylib 0x1f75b7004 _dispatch_main_queue_callback_4CF$VARIANT$mp 9 CoreFoundation 0x1f7b5ac1c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE 10 CoreFoundation 0x1f7b55b54 __CFRunLoopRun 11 CoreFoundation 0x1f7b550b0 CFRunLoopRunSpecific 12 GraphicsServices 0x1f9d5579c GSEventRunModal 13 UIKitCore 0x2244cf978 UIApplicationMain 14 Qpay 0x102253268 main + 16 (GeneratePasscodeInteractor.swift:16) 15 libdyld.dylib 0x1f761a8e0 start

    Haptica version:- 3.0.0 Thanks

    opened by raviatri 1
  • Update Hapticable.swift

    Update Hapticable.swift

    'cannot assign to property' fix

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    this change will solve cannot assign to property: 'self' is immutable error for cases when trying to assign property inside subclass c-tor

    Sample code:

    class MyButtonSubclass: UIButton {
        override init(frame: CGRect) {
            super.init(frame: frame)
            isHaptic = true
            hapticType = .impact(.heavy)
        }
    }
    
    opened by Kirow 1
  • Swift 5.0

    Swift 5.0

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Description

    • Added Swift 5.0 Support
    opened by efremidze 0
  • 2.2.2

    2.2.2

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Description

    Lowers the Deployment Target to 9.0 whereas for devices lower than iOS 10 it simply does nothing.

    opened by efremidze 0
  • Lower Deployment Target to 9.0

    Lower Deployment Target to 9.0

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Motivation and Context

    Library is hard/impossible to use via carthage if the host project has a Deployment Target of 9.0. I do know that inside the CONTRIBUTING.md it is stated to not lower the deployment target. But still, I would prefer to at least have the option to use the framework and add extra functionality with ease for my users that are >=iOS 10.0 without any hassle.

    Description

    Lowers the Deployment Target to 9.0 whereas for devices lower than iOS 10 it simply does nothing.

    opened by EternalBlack 0
  • How to stop while playing a note

    How to stop while playing a note

    How to stop while playing a long pattern

    Haptic.play("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", delay: 0.1)

    I want to stop this when this is playing. Please show me a way to do it.

    thanks

    opened by amith-ranasinghe 1
  • How do you do a double tap?

    How do you do a double tap?

    I tried with the following pattern but nothing simulates a double tap, how do I do that?

    addButton(pattern: "O") addButton(pattern: "o") addButton(pattern: ".") addButton(pattern: ".-.") addButton(pattern: "o-o") addButton(pattern: "O-O") addButton(pattern: "..oO-Oo..") addButton(pattern: "O--O") addButton(pattern: "o--o") addButton(pattern: "o---o") addButton(pattern: "O---O") addButton(pattern: "o--O--O--o") addButton(pattern: "o--O---O--o") addButton(pattern: "O--O---O--O") addButton(pattern: "OOO------------------------OOO")

    opened by dpyy 0
  • Usage in table view?

    Usage in table view?

    Thanks for this great library!

    I'm trying to use it in a table view, and I have the following code:

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      Haptic.impact(.medium).generate()
      // Other stuff...
    }
    

    This generates haptic feedback, but sometimes it seems to be generating two very fast consecutive ones. It happens when you click on one cell and then another.

    Is it the wrong way to use the library? Thank you!

    opened by danqing 0
Releases(3.0.3)
Owner
Lasha Efremidze
#iOS Engineer @amzn @EdisonJunior (Ring). Previously @eBay @stubhub @calaborate (Klutch). Open source enthusiast.
Lasha Efremidze
TapticEngine generates haptic feedback vibrations on iOS device.

TapticEngine Overview TapticEngine generates haptic feedback vibrations on iOS device. This library wrapps on UIImpactFeedbackGenerator, UISelectionFe

WorldDownTown 253 Oct 28, 2022
🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring

Location Manager Made Easy SwiftLocation is a lightweight Swift Library that provides an easy way to work with location-related functionalities. No mo

Daniele Margutti 3.2k Dec 30, 2022
WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS.

WatchCon WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS Requirements iOS 9.0+ / watchOS 2.0+ CocoaPods CocoaPods

Abdullah Selek 33 Sep 22, 2022
Haptico 📳 - easy to use haptic feedback generator with pattern-play support

Haptico Haptico is easy to use iOS haptic feedback generator. Besides default haptic feedbacks it can play patterns! Checkout Example project. Table o

Sapozhnik Ivan 462 Jan 1, 2023
Easy Haptic Feedback Generator 📳

Haptica is an easy haptic feedback generator. $ pod try Haptica Requirements iOS 9.0+ Xcode 8.0+ Swift 5 (Haptica 3.x), Swift 4 (Haptica 2.x), Swift

Lasha Efremidze 702 Jan 1, 2023
TapticEngine generates haptic feedback vibrations on iOS device.

TapticEngine Overview TapticEngine generates haptic feedback vibrations on iOS device. This library wrapps on UIImpactFeedbackGenerator, UISelectionFe

WorldDownTown 253 Oct 28, 2022
✨ Super easy Parallax and Haptic Effect.

IParallaxAndHapticEffect ✨ Super easy Parallax and Haptic Effect. This library helps you easily use the 'Parallax' and 'Haptic' effects. Customized 3D

Hae Chan 2 Feb 9, 2022
Spin aims to provide a versatile Feedback Loop implementation working with the three main reactive frameworks available in the Swift community (RxSwift, ReactiveSwift and Combine)

With the introduction of Combine and SwiftUI, we will face some transition periods in our code base. Our applications will use both Combine and a thir

Spinners 119 Dec 29, 2022
PinpointKit is an open-source iOS library in Swift that lets your testers and users send feedback with annotated screenshots using a simple gesture.

PinpointKit is an open-source iOS library in Swift that lets your testers and users send feedback with annotated screenshots using a simple gesture. F

Lickability 1.1k Jan 6, 2023
Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.

SPAlert Popup from Apple Music & Feedback in AppStore. Contains Done, Heart, Error and other presets. Supports Dark Mode. I tried to recreate Apple's

Ivan Vorobei 1.8k Jan 7, 2023
Butterfly is a lightweight library for integrating bug-report and feedback features with shake-motion event.

Butterfly is a lightweight library for integrating bug-report and feedback features with shake-motion event. Goals of this project One of th

Zigii Wong 410 Sep 9, 2022
Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.

SPAlert Popup from Apple Music & Feedback in AppStore. Contains Done, Heart, Error and other presets. Supports Dark Mode. I tried to recreate Apple's

Ivan Vorobei 1.4k Dec 10, 2021
🐛 WormTabStrip ViewPager for iOS written in Swift, which gives continuous feedback to the user when scrolling

Worm Tab Strip Worm Tab Strip is inspired by android SmartTabStrip, android view pager like library for iOS written in swift. Basically it was build u

EzimetYusup 176 Dec 13, 2022
A custom ViewPager title strip which gives continuous feedback to the user when scrolling

SmartTabLayout A custom ViewPager title strip which gives continuous feedback to the user when scrolling. This library has been added some features an

ogaclejapan 7k Dec 30, 2022
Pendo captures product usage data, gathers user feedback, and lets you communicate in-app to onboard, educate, and guide users to value

Pendo SDK for IOS The Pendo Mobile SDK is a code-less, retro-active analytics collector across all of your app's versions. The SDK also allows present

Pendo 30 Jan 4, 2023
LayoutLoopHunter - Runtime-based setup for tracking autolayout feedback loops

LayoutLoopHunter The library helps to catch the OOMs caused by Autolayout Feedback Loop by replicating the behavior of UIViewLayoutFeedbackLoopDebuggi

Ruslan Serebriakov 108 Oct 1, 2022
In-app feedback and bug reporting tool for apps.

Instabug iOS SDK Instabug is an in-app feedback and bug reporting tool for mobile apps. With just a simple shake, your users or beta testers can repor

Instabug 274 Dec 14, 2022
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
OpenAPI/Swagger 3.0 Parser and Swift code generator

SwagGen SwagGen is a library and command line tool for parsing and generating code for OpenAPI/Swagger 3.0 specs, completely written in Swift. Swagger

Yonas Kolb 568 Jan 5, 2023