GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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)

1      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.

Click to save your free 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.