How to make iPhone vibrate using Swift?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In iOS, "make the phone vibrate" can mean two slightly different things. You might want the classic system vibration, or you might want modern haptic feedback that feels lighter and more intentional for taps, successes, warnings, and impacts.
The right API depends on the effect you want and the iOS version you support. For simple feedback, UIKit haptic generators are usually the best choice. For custom patterns on supported devices, CoreHaptics gives finer control.
Use UIKit Haptic Generators For Most Apps
If your goal is user feedback during normal app interactions, start with the built-in haptic generators. They are simple, expressive, and better aligned with iOS design than triggering a generic vibration for every event.
UINotificationFeedbackGenerator is a good fit for success, warning, and error moments. For taps or physical-feeling interactions, UIImpactFeedbackGenerator is often better:
The call to prepare() is optional, but it can reduce latency when you know feedback is likely to happen very soon, such as immediately after a button press or drag gesture.
Trigger The Classic Vibration
If you specifically want the older system vibration effect, you can still use AudioToolbox. This is the closest answer to "make the iPhone vibrate" in the traditional sense.
That API is straightforward, but it gives you far less control than UIKit haptics or CoreHaptics. It is best used sparingly, usually for legacy behavior or when the generic vibration is exactly what you need.
Create Richer Patterns With CoreHaptics
For supported devices running modern iOS versions, CoreHaptics lets you design more customized feedback. This is useful for games, media tools, or interactions where the default UIKit styles are not expressive enough.
This gives you access to transient and continuous events, intensity control, and more advanced patterns. The tradeoff is more setup and the need to handle unsupported hardware cleanly.
Pick The API Based On Intent
A useful rule is to think in terms of product intent instead of implementation detail. If the app wants to say "success" or "warning," use the notification generator. If it wants to simulate an impact, use the impact generator. If it needs a custom tactile pattern, use CoreHaptics. If it really just needs the classic device vibration, AudioToolbox is still available.
This approach keeps your code easier to maintain and produces feedback that feels more natural on iOS. Users notice when haptics are used thoughtfully, and they also notice when every minor action causes a heavy vibration.
Common Pitfalls
One common mistake is assuming all Apple devices behave the same way. Some devices support rich haptics, others support only more limited feedback, and the simulator cannot represent hardware vibration accurately. Another mistake is overusing vibration. Constant haptic feedback quickly becomes annoying and can make the app feel cheap rather than polished. Developers also sometimes trigger the feedback too late because the generator is created long after the interaction begins. Creating or preparing the generator close to the gesture often improves responsiveness. Finally, do not rely on vibration as the only channel for important information. It should reinforce a visual or audio cue, not replace accessible communication.
Summary
- Use UIKit haptic generators for most tap, success, warning, and impact feedback.
- Use
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)for the classic vibration effect. - Use
CoreHapticswhen you need custom tactile patterns on supported devices. - Call
prepare()when low-latency feedback matters. - Test on real hardware and use haptics sparingly so the feedback remains meaningful.

