Home > front end >  Vibrate one time Taptic
Vibrate one time Taptic

Time:06-17

How to make iPhone soft vibrate one time? Below code vibrates twice. Is there any way to check how many times vibrate occur in simulator? :)

let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success) // .error .warning

CodePudding user response:

  1. You can't test vibration on a simulator, Need to use a real device for checking vibrations.

  2. for soft vibration, you can use UISelectionFeedbackGenerator and can also use UIImpactFeedbackGenerator with soft style like this:

// UISelectionFeedbackGenerator

let generator = UISelectionFeedbackGenerator()
    generator.selectionChanged()

// UIImpactFeedbackGenerator

let feedbackGenerator = UIImpactFeedbackGenerator(style: .soft)
 feedbackGenerator.impactOccurred()
  • Related