Haptico Documentation

repository·master·Indexed 19 days ago

https://github.com/isapozhnik/haptico

An iOS library for generating haptic feedback, including standard system notifications (Success, Warning, Error), impact feedbacks (light, medium, heavy), and custom playable patterns. Includes UI extensions such as HapticoButton and UIAlertController integration. Supports installation via CocoaPods, Carthage, and Swift Package Manager.

Tokens
1.1K
Snippets
5
Records
7
Agent score
18%

What's inside Haptico

  1. Manage transparency in App Icons

    master

    iTunesConnect does not support images with alpha channels or transparencies for application icons. Any transparent pixels in your source images will be converted into solid black during the submission process.

    Best Practice: To avoid unexpected black backgrounds, adjust the transparency settings in your source files (removing alpha channels) before using makeAppIcon or submitting to iTunesConnect.

  2. Handle iTunesArtwork & iTunesArtwork@2x (App Icon) file extensions

    master

    When preparing App Icons for iTunesConnect submission, the .png extension must be prepended to the iTunesArtwork and iTunesArtwork@2x files. Haptico handles this automatically for you.

    Important for Ad-hoc or Enterprise distribution: If you are distributing via Ad-hoc or Enterprise methods, you must manually remove the .png extension from these files before adding them to Xcode to prevent errors.

  3. Install Haptico via CocoaPods, Carthage, or Swift Package Manager

    master

    Haptico can be integrated into your iOS project using several dependency managers:

    CocoaPods

    Add this line to your Podfile:

    pod 'Haptico'

    Carthage

    Add this line to your Cartfile:

    gituh "iSapozhnik/Haptico"

    Swift Package Manager

    Add the repository URL as a dependency in your Package.swift or via Xcode's package dependency interface:

    dependencies: [
        .package(url: "https://github.com/iSapozhnik/Haptico.git", from: "1.1.0"),
    ],
  4. Generate impact haptic feedbacks

    master

    For more granular tactile feedback, use Haptico.shared().generate(_:) with the HapticoImpact enum.

    Requirements: This feature requires iOS 10+ and a device with a haptic engine (starting from iPhone 7).

    Supported Impacts:

    • .light
    • .medium
    • .heavy
    import Haptico
    
    // Example usage
    Haptico.shared().generate(.medium)
  5. Use Haptico UI Extensions

    master

    Haptico provides built-in UI components and extensions to simplify haptic integration in your interface:

    HapticoButton

    HapticoButton is a subclass of UIButton. To use it:

    1. Set the class name to HapticoButton in your Storyboard.
    2. It automatically triggers haptics based on touch events:
      • UIControlEvents.touchDown: Triggers a heavy impact.
      • UIControlEvents.touchUpInside or touchUpOutside: Triggers a light impact.

    UIAlertController Extension

    You can trigger haptic notifications directly when presenting a UIAlertController using the hapticNotification parameter.

    import UIKit
    import Haptico
    
    func showSuccessAlert() {
        let alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
        
        // Triggers a success haptic notification upon presentation
        present(alert, animated: true, hapticNotification: .success)
    }
  6. Play custom haptic patterns using Pattern Play

    master

    Haptico allows you to play custom haptic sequences defined by a string pattern using generateFeedbackFromPattern(_:delay:).

    Pattern Syntax:

    • O (capital O): Heavy impact
    • o (lowercase o): Medium impact
    • . (dot): Light impact
    • - (hyphen): Delay (duration of 0.1 second)

    Requirements: Pattern play and impacts are not supported on devices prior to iPhone 7 or iOS 10.

    import Haptico
    
    // Plays a sequence of light, medium, heavy, and delayed impacts
    Haptico.shared().generateFeedbackFromPattern("..oO-Oo..", delay: 0.1)
  7. Generate predefined haptic notifications

    master

    You can trigger standard haptic notification patterns (Success, Warning, or Error) using the Haptico.shared().generate(_:) method with the HapticoNotification enum.

    Supported Notifications:

    • .success
    • .warning
    • .error

    Note: These are available on all supported devices.

    import Haptico
    
    // Example usage
    Haptico.shared().generate(.success)
    Haptico.shared().generate(.warning)
    Haptico.shared().generate(.error)