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 Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.