I have never coded an app, but I just got Chat GPT 4 to write the code for a very basic iPhone vibration app. I can’t help anyone, other than to share the code, but I thought I would let people know it’s possible. Looks like it could be customizable too.
iPhone vibration app: I have never coded an... - Cure Parkinson's
iPhone vibration app
Pretty much what cue1 does
simple and effective, Triever7
Here is a study on the subject:
pmc.ncbi.nlm.nih.gov/articl...
Fed1000
with regard to the Emma watch which has been researched I am trying to find out if it will be made available anytime in the foreseeable future
how brilliant. Could you send me the code please, or tell me what you typed into chat GPT so I can do it for myself?
I wonder if this is similar to the beech band which I am waiting for. I found the cue to be too overstimulating for me
can you share code?
this is the code. Deployment iOS 18.2 or later. Still buggy - does not run in the background and I have to close out and reopen to get it to start again. I have not integrated Apple Watch.
import SwiftUI
import CoreHaptics
struct ContentView: View {
@State private var engine: CHHapticEngine?
@State private var frequency: Double = 150.0 // Hz
@State private var intensity: Double = 0.5 // 0.0 to 1.0
@State private var duration: Double = 1.0 // Seconds
@State private var isPlaying = false
var body: some View {
VStack(spacing: 20) {
Text("Vibration Control")
.font(.largeTitle)
.bold()
// Frequency Slider
VStack {
Text("Frequency: \(Int(frequency)) Hz")
Slider(value: $frequency, in: 1...300, step: 1)
}
// Intensity Slider
VStack {
Text("Intensity: \(String(format: "%.2f", intensity))")
Slider(value: $intensity, in: 0.0...1.0, step: 0.01)
}
// Duration Slider
VStack {
Text("Duration: \(String(format: "%.2f", duration)) seconds")
Slider(value: $duration, in: 0.1...10.0, step: 0.1)
}
// Play/Stop Button
Button(action: toggleHaptic) {
Text(isPlaying ? "Stop Vibration" : "Start Vibration")
.font(.headline)
.padding()
.frame(maxWidth: .infinity)
.background(isPlaying ? Color.red : Color.green)
.foregroundColor(.white)
.cornerRadius(10)
}
}
.padding()
.onAppear(perform: prepareHaptics)
}
func prepareHaptics() {
guard CHHapticEngine.capabilitiesForHardware().supportsHaptics else {
print("Haptics not supported on this device.")
return
}
do {
engine = try CHHapticEngine()
try engine?.start()
} catch {
print("Failed to start haptic engine: \(error.localizedDescription)")
}
}
func playHaptic() {
guard let engine = engine else { return }
do {
let intensityParameter = CHHapticEventParameter(parameterID: .hapticIntensity, value: Float(intensity))
let sharpnessParameter = CHHapticEventParameter(parameterID: .hapticSharpness, value: 0.5)
let event = CHHapticEvent(
eventType: .hapticContinuous,
parameters: [intensityParameter, sharpnessParameter],
relativeTime: 0,
duration: duration
)
let pattern = try CHHapticPattern(events: [event], parameters: [])
let player = try engine.makePlayer(with: pattern)
try player.start(atTime: 0)
} catch {
print("Failed to play haptic: \(error.localizedDescription)")
}
}
func toggleHaptic() {
if isPlaying {
engine?.stop(completionHandler: nil)
isPlaying = false
} else {
playHaptic()
isPlaying = true
}
}
}
@main
struct VibrationControlApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
I prompted it by asking it about the Beech Band and Tass gloves and asking if it could code an app that met these specifications. Its not perfect, but it runs. Happy to take friendly amendments. I am no expert at this, though I see the logic of it. I write code for data analysis.
what does the vibration app control? Is it compatible with the apple watch?
it controls the phone, which allows custom haptics. It can be integrated with the watch but I haven’t tried. I’ve been using a haptic metronome app for that. It’s called Haptik, but there are many. Really just kind of nodding around waiting for products to actually arrive
thanks heaps
hi Triver! Where does the code go to create the IPhone app? Is there a developer app where the code can be copy pasted to? Thank you in advance !!!!
the program is called Xcode. If you paste all that code into chat gpt and ask for step by step installation instructions, you should get them. Remember, this is iPhone running on iOS 18.2 . Other than that, I have no expertise.