How to Make iPhone Vibrate Using Swift
In this article
You can make an iPhone vibrate from your Swift code by calling the system haptic feedback APIs: for most app interactions use UIImpactFeedbackGenerator, for selection changes use UISelectionFeedbackGenerator, and for success, warning or error feedback use UINotificationFeedbackGenerator. These are the only officially supported ways to trigger vibration from an app. There is no public API that produces a continuous, arbitrary-length vibration, and the old AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) call still works but is limited and not recommended for modern apps. The steps below show how to set up and use the feedback generators correctly, including preparation, timing and cleanup.
What You'll Need
- A Mac with Xcode installed (any recent version).
- An iPhone running a current version of iOS. The Simulator does not vibrate, so you must test on a real device.
- A basic SwiftUI or UIKit project. The code is the same in both; only the place where you call it differs.
- No special entitlements, permissions or frameworks. Haptic feedback is part of UIKit and works without asking the user for anything.
Step-by-Step
- Decide which feedback type matches the action. Use impact feedback for physical-feeling taps (a button press, a card snapping into place), selection feedback for moving through a picker or changing a segmented control, and notification feedback for the result of an operation (success, warning, error). Picking the right generator matters because iOS tunes each one differently, and using the wrong one feels off to users.
- Create the generator close to where you will use it. In SwiftUI, declare it as a property inside your view or a small helper type. In UIKit, create it in the view controller. For example:
let impact = UIImpactFeedbackGenerator(style: .medium). The style can be.light,.medium,.heavy,.softor.rigid; medium is a safe default for a normal button tap. - Call
prepare()before the user is likely to trigger the feedback. This wakes up the haptic engine so the vibration fires without delay. A good place is when the screen appears or when a touch begins. Callingprepare()too early (many seconds before the tap) wastes power and the engine may go back to sleep, so keep it within a second or two of the expected interaction. - Trigger the feedback at the moment of the action. For impact:
impact.impactOccurred(). For selection:UISelectionFeedbackGenerator().selectionChanged(). For notification:UINotificationFeedbackGenerator().notificationOccurred(.success), where the argument can be.success,.warningor.error. Put the call inside the button action or the state change handler, not in a view'sbody, or it will fire repeatedly during redraws. - Keep a reference if you reuse the generator. Creating a new generator on every tap works but is slightly less responsive. Storing one instance and calling
prepare()again before the next use gives the best timing. Generators are lightweight, so a single stored instance per screen is enough. - Test on a physical iPhone. Run the app from Xcode onto a connected device, then trigger the action. The Simulator shows no vibration at all, so a silent Simulator does not mean your code is wrong. Also check that the phone is not in Silent mode with vibration disabled in Settings > Sounds & Haptics, and that the device actually has a haptic engine (all modern iPhones do; older models may not).
- Respect the user's settings. iOS automatically suppresses haptics when the user has turned off system haptics or when Low Power Mode is active in some cases. You do not need to check these yourself; just do not build critical information around vibration alone, because some users will never feel it.
Common Mistakes
- Calling the generator inside
bodyorviewDidLoad. This fires the vibration at unexpected times, often repeatedly. Trigger it only in response to a user action or a deliberate state change. - Expecting the Simulator to vibrate. It never will. Always confirm on a real iPhone before assuming something is broken.
- Using
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)for everything. It works, but it ignores the haptic styles, cannot be prepared for low latency, and is considered legacy. Use the feedback generators instead. - Forgetting
prepare(). Without it the first vibration can lag by a noticeable fraction of a second, which feels broken during fast interactions. - Overusing haptics. Vibrating on every scroll or every minor update is annoying and drains battery. Reserve feedback for meaningful moments.
- Assuming vibration equals notification. Haptic feedback is not a substitute for a local notification; it only fires while your app is in the foreground and you call it.
Tips
- Match intensity to importance: light impact for small toggles, medium for primary buttons, heavy or rigid for destructive confirmations.
- Pair a notification haptic with a visual change (a checkmark, a red banner) so users who cannot feel vibration still get clear feedback.
- Call
prepare()on touch-down andimpactOccurred()on touch-up for a natural feel in custom controls. - Use
UISelectionFeedbackGeneratorfor pickers and segmented controls; it produces the subtle tick users already associate with those controls. - Keep generators as properties rather than creating them in a loop; it is cleaner and slightly faster.
- Test with Silent mode on and off, and with system haptics disabled, to see how your app behaves for users who turn vibration off.
Troubleshooting
If nothing happens, work through these checks in order. First, confirm you are on a real iPhone, not the Simulator. Second, check Settings > Sounds & Haptics and make sure haptics are enabled and the phone is not in a mode that disables vibration. Third, verify your call actually runs: add a breakpoint or a print statement in the button action. Fourth, make sure the generator is not being deallocated before it fires; if you create it locally and the call happens later, store it as a property. Fifth, try a different feedback style to rule out a very subtle setting like .soft being hard to feel. Sixth, restart the iPhone and rebuild the app; occasional haptic engine glitches clear after a restart. If the app was just installed, trigger the feedback once, wait a moment, then trigger again, since the engine sometimes needs a warm-up. If it still fails, check that you have not wrapped the call in a condition that is false at runtime.
Frequently Asked Questions
Can I make the iPhone vibrate continuously for a set duration?
No. iOS does not expose a public API for a sustained vibration of arbitrary length. You can only trigger short haptic feedback events. For alerts, use local notifications with sound and vibration configured by the system.
Does haptic feedback work in the iOS Simulator?
No. The Simulator does not reproduce vibration. You must test on a physical iPhone.
Do I need permission to use haptics?
No. Haptic feedback requires no user permission and no special entitlement. It is part of UIKit.
Why does my vibration feel delayed?
Most likely you are not calling prepare() shortly before the interaction, or you are creating a new generator at the last moment. Prepare the generator on touch-down or when the screen appears.
Will haptics work if the user has disabled vibration?
iOS respects the user's system settings. If the user has turned off haptics, your calls may produce no vibration. Do not rely on vibration as the only feedback.
Is AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) still allowed?
It still functions, but it is a legacy approach with no style control and no preparation step. Apple's recommended approach is the feedback generator classes.