WWDC24 SALE: Save 50% on all my Swift books and bundles! >>

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)

   

Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.