Skip to content

fix(@capacitor/haptics): prevent thread overload by reusing CHHapticEngine #2340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GorkaMinus
Copy link

Fix: Prevent iOS app freeze by reusing CHHapticEngine instance

This PR addresses an issue where calling Haptics.vibrate() rapidly (e.g., from a fast-scrolling picker in my case) causes the app to hang or crash on iOS. The problem stems from creating a new CHHapticEngine instance on each call, which leads to excessive thread creation and eventual system overload.

Solution

  • Reuses a single CHHapticEngine instance across multiple vibration calls.
  • Ensures the engine is only created and started when necessary.
  • Handles engine lifecycle and failure states gracefully.

This fix improves performance and stability, especially in high-frequency vibration scenarios.

Related Issue #1960

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant