Luc-Olivier
Luc-Olivier

Reputation: 3973

UINotificationFeedbackGenerator & UIImpactFeedbackGenerator doesn't work for me on iPhone6S / iOS 14.3. Does any body had the same issue?

I experienced a strange Haptic behavior on iPhone6S / iOS 14.3.

UINotificationFeedbackGenerator()
&
UIImpactFeedbackGenerator()

don't produce any vibrations

while

 AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

do it.

I confirmed with the same simple code on an iPhone XR where both work.

import SwiftUI
import AVFoundation

struct ContentView: View {
    
      func simpleSuccess() {
           let generator = UINotificationFeedbackGenerator()
           generator.notificationOccurred(.error)
      }

      func otherVibration() {
           print("#")
           AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
      }

      var body: some View {
           VStack {
                Text("UINotificationFeedbackGenerator")
                .onTapGesture(perform: simpleSuccess)
                .padding(.bottom, 60)
                Text("AudioServicesPlayAlertSound")
                .onTapGesture(perform: otherVibration)
            }
      }
}

Upvotes: 0

Views: 407

Answers (2)

Luc-Olivier
Luc-Olivier

Reputation: 3973

I found a good way to know if the model support or not haptics

import CoreHaptics

print(CHHapticEngine.capabilitiesForHardware().supportsHaptics ? "Yes" : "No")

Upvotes: 0

El Tomato
El Tomato

Reputation: 6707

According to Apple, not all models support the haptic feedback. iPhone 6S doesn't support it.

Upvotes: 2

Related Questions