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
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"]),
]
)
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>
Add the following line to your code where you play your pattern
import HaptrixSync
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 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()
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.
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)
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
HaptrixSync is written and maintained by Chris Davis.
Twitter: @nthState.
HaptrixSync is released under the MIT License.
See LICENSE for details.
link |
Stars: 0 |
Last commit: 4 weeks ago |
c119025
- Change Bump versions to run on workflow dispatch (commit by @nthState)eb0dc72
- Add token parameter to changelog action (commit by @nthState)6fe7d64
- update CHANGELOG.md for v0.0.0+5 [skip ci]adb2a04
- Format YAML (commit by @nthState)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)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