1

Now I have an extension to make the device vibrate from anywhere in the app:

extension UIDevice {
    static func vibrate(style: UINotificationFeedbackGenerator.FeedbackType) {
        guard CHHapticEngine.capabilitiesForHardware().supportsHaptics else {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
            return
        }
        let generator = UINotificationFeedbackGenerator()
        generator.notificationOccurred(style)
    }
}

The problem is with the devices, that uses haptics. Now I am using style as warning but the device vibration is very weak, not even noticeable. Is there another way to make the device vibrate 2 times, or more intense?

I have tried different vibration styles in code, but vibration is still very weak.

Jkrist
  • 748
  • 1
  • 6
  • 24

1 Answers1

1

There is function to do that in CoreHaptic, here the tutorial

// Create an intensity parameter:
let intensity = CHHapticEventParameter(parameterID: .hapticIntensity,
                                       value: initialIntensity)

// Create a sharpness parameter:
let sharpness = CHHapticEventParameter(parameterID: .hapticSharpness,
                                       value: initialSharpness)

// Create a continuous event with a long duration from the parameters.
let continuousEvent = CHHapticEvent(eventType: .hapticContinuous,
                                    parameters: [intensity, sharpness],
                                    relativeTime: 0,
                                    duration: 100)

do {
    // Create a pattern from the continuous haptic event.
    let pattern = try CHHapticPattern(events: [continuousEvent], parameters: [])
    
    // Create a player from the continuous haptic pattern.
    continuousPlayer = try engine.makeAdvancedPlayer(with: pattern)
    
} catch let error {
    print("Pattern Player Creation Error: \(error)")
}

continuousPlayer.completionHandler = { _ in
    DispatchQueue.main.async {
        // Restore original color.
        self.continuousPalette.backgroundColor = self.padColor
    }
}
aiwiguna
  • 2,852
  • 2
  • 15
  • 26