Home > Software design >  UINotificationFeedbackGenerator & UIImpactFeedbackGenerator doesn't work for me on iPhone6S / i
UINotificationFeedbackGenerator & UIImpactFeedbackGenerator doesn't work for me on iPhone6S / i

Time:10-03

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)
            }
      }
}

CodePudding user response:

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

CodePudding user response:

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

import CoreHaptics

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