Play Vibration Tutorial

The iPhone has the built-in ability to alert the user with a vibration. Using the System Sound services the vibration can be triggered. In this tutorial the vibration will be triggered 5 times. This tutorial is made with Xcode 7 and built for iOS9. Note this app is built for a real devices, since the iOS Simulator doesn't have vibration.

Open Xcode and create a new Single View Application. For product name, use IOS9VibrationTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and make sure only iPhone is selected in Devices.

Go to the Storyboard. Drag a Button from the Object Library to the top of the main View. Double-click the Button and set the title to "Start". Ctrl + Drag to the top of the main view and select the "Vertical Spacing to Top Layout Guide" and "Center Horizontally in Container". options.

The Storyboard should look like this

Select the Assistant Editor and make sure the ViewController.swift is visible. Ctrl and drag from the Button and create the following Action.

Go to the ViewController.swift file and import the AudioToolbox framework

import AudioToolbox

Implement the startVibration method.

@IBAction func startVibration(sender: AnyObject) {
  for _ in 1...5 {

The AudioServicesPlaySystemSound method plays the vibration using the kSystemSoundID_Vibrate constant.The sleep delays 1 second for the next vibration starts, otherwise the vibration is still running. Build and Run the project on an iPhone, press the start button and the device will vibrate 5 times.

You can download the source code of the IOS9VibrationTutorial at the ioscreator repository on Github.