Swiftpack.co - nthState/HaptrixSync as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nthState.
nthState/HaptrixSync v1.0.0+1
Update your Apps Haptics on the fly
⭐️ 0
🕓 4 weeks ago
iOS macOS
.package(url: "https://github.com/nthState/HaptrixSync.git", from: "v1.0.0+1")

Unit Test SPM

Haptrix Sync

Update your App's Haptics without re-compiling your App.

This package allows you to change your Haptic file and send it to your App directly from the Haptrix App

Table of Contents

  1. Features
  2. Requirements
  3. Installation
  4. Usage
    1. Syncing from Haptrix to your App
    2. Playing a pattern
    3. Debug Release Builds
  5. Advanced Usage
    1. Using a publisher
  6. New Developer?
  7. Credits
  8. License

Features

  • ☑ No need to re-build your app to test your latest Haptic
  • ☑ Trigger the Haptic from your App, it will play your latest Haptic
  • ☑ Faster Development time

Requirements

  • iOS 13.0+
  • Xcode 11.0

Installation

Swift Package Manager

The Swift Package Manager is a dependency manager integrated with the Swift build system. To learn how to use the Swift Package Manager for your project, please read the official documentation.
To add HaptrixSync as a dependency, you have to add it to the dependencies of your Package.swift file and refer to that dependency in your target.

// swift-tools-version:5.0
import PackageDescription
let package = Package(
    name: "<Your Product Name>",
    dependencies: [
    .package(url: "https://github.com/nthState/HaptrixSync.git", "main")
    ],
    targets: [
        .target(
    name: "<Your Target Name>",
    dependencies: ["HaptrixSync"]),
    ]
)

Update your Info.plist

You will need to add the following lines to your Info.plist, this tells your app that it can connect to the Haptrix macOS App. The NSLocalNetworkUsageDescription is required key to ask the user for permission to connec to the Haptrix App.

<key>NSBonjourServices</key>
<array>
  <string>_haptrix._tcp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>Network usage is required for macOS/iOS communication</string>

Import the framework

Add the following line to your code where you play your pattern

import HaptrixSync

Usage

Syncing from Haptrix to your App

Ensure your App and Haptrix macOS App are running & connected.

Make a change to your *.AHAP file in Haptrix macOS and press Run on device - the *.AHAP file is sent to your App, so that the next time you play your Haptic, the very latest Haptic will play.

Question: How does HaptrixSync know what file to update? We use the fileName of the *.AHAP file.

Playing a Pattern

Playing a pattern is simple, the method signature is almost identical to CHHapticEngine playPattern method. Supply the syncUpdates: true and the App will connect to the Haptrix macOS App.


let engine = CHHapticEngine()

engine.playPattern(from: url, syncUpdates: true)

Note: By default, the playPattern method will connect on the first play of any pattern, however, if you wish to prepare you need to call:


let engine = CHHapticEngine()

engine.prepareSyncing()

Debug Release Builds

This package is designed so that it helps you develop your App, to that end, I suggest you don't ship this package in your release builds.

You can try something like:

#if DEBUG
engine.playPattern(from: url, syncUpdates: true) // HaptrixSync Player
#else
engine.playPattern(from: url) // Standard engine player
#endif

A better solution would be to remove the dependency on release builds.

Advanced Usage

Using a publisher

If you want to use a combine publisher to know when your Haptic file has finished playing, I've got you covered.


let engine = CHHapticEngine()

var cancellables = Set<AnyCancellable>()

engine
  .playPatternPublisher(from: url, syncUpdates: true)
  .sink { result in
    switch result {
    case .failure(let error):
      os_log("Error: %@", log: .haptics, type: .error, "\(error)")
    case .finished:
      os_log("Finished", log: .haptics, type: .debug)
    }
  } receiveValue: { value in
    os_log("Pattern played: %@", log: .haptics, type: .debug, named)
  }
  .store(in: &cancellables)

New Developer?

If you are a new developer, we have a script you can run to install all dependencies, there may be parts that you do-not wish to install, so pick and choose what you need from the script

./Scripts/new-developer.sh

Credits

HaptrixSync is written and maintained by Chris Davis.
Twitter: @nthState.

License

HaptrixSync is released under the MIT License.
See LICENSE for details.

GitHub

link
Stars: 0
Last commit: 4 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Release Notes

v1.0.0+1
7 weeks ago

:bug: Bug Fixes

  • c119025 - Change Bump versions to run on workflow dispatch (commit by @nthState)
  • eb0dc72 - Add token parameter to changelog action (commit by @nthState)

:memo: Documentation Changes

  • 6fe7d64 - update CHANGELOG.md for v0.0.0+5 [skip ci]

:art: Code Style Changes

  • adb2a04 - Format YAML (commit by @nthState)

:wrench: Chores

  • 1356bb8 - Add .github folder with default workflows (commit by @nthState)
  • c3694b1 - Add new developer script, codeowners, update README (commit by @nthState)
  • b1253d7 - test bump on branch (commit by @nthState)
  • e411bf1 - Expand checkout with token (commit by @nthState)
  • 9424813 - Fix repo name (commit by @nthState)
  • d8045a8 - bump changelog to 1.7.0 (commit by @nthState)
  • 3e60930 - Add IDETemplateMacros.plist (commit by @nthState)
  • bc281db - Fix bad merge (commit by @nthState)

:flying_saucer: Other Changes

  • cbfbc32 - Package now supports macOS (commit by @nthState)
  • 5b819cf - Bump minimum macOS Version (commit by @nthState)
  • a9f0a9c - Bump macOS Version to 10.15 (commit by @nthState)
  • a933978 - Differentiating the names of the methods, one uses a publisher, the other can throw an error (commit by @nthState)
  • de66f62 - allowLocalEndpointReuse (commit by @nthState)
  • 3190dfc - Remove allowLocalEndpointReuse (commit by @nthState)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics