TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: [Day 50] .sensoryFeedback() modifier not causing haptic feedback

Forums > 100 Days of SwiftUI

I'm testing the code on an iPhone 14 Pro that has developer mode turned on. I also recreated a new project with the same code (below) and I still can't get the haptics to work. Is there anything in my phone's settings I need to turn on for this to work?

import SwiftUI

struct HapticFeedback: View {

    @State private var counter = 0
    var body: some View {
            Button("Press Me: \(counter)") {
                increaseNumber()
            }
            .sensoryFeedback(.increase, trigger: counter)
    }
    func increaseNumber() {
        counter += 1
    }
}

#Preview {
    HapticFeedback()
}

   

UPDATE

I've found the issue. "System Haptics" needs to be turned on in Settings. For those who run into this problem:

  • -> Settings
  • -> Sounds & Haptics
  • -> System Haptics (turn on)

   

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.