How to trigger vibration on Apple Watch OS 2?

Jiri picture Jiri · Sep 2, 2015 · Viewed 8.2k times · Source

I have been working with Apple Watch OS 2 for a while, but have not succeeded in triggering vibration on Apple Watch standalone app in Swift, using Xcode Version 7.0 beta 6 (7A192o).

All tutorials using vibration on iPhone in Swift look like:

 import AudioToolbox
 ...
 AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

But I cannot import the AudioToolbox library.

I get the error:

Could not build Objective-C module "AudioToolbox"

Has anyone already found the way to do it?

Answer

LucPts picture LucPts · Sep 3, 2015

You can generate haptic & auditory feedback, using:

WKInterfaceDevice.currentDevice().playHaptic(.Click)

'Click' is one of the 'cases' (types of vibration/beeps) that you can choose, cfr:

enum WKHapticType : Int {
 

case Notification
 
case DirectionUp

case DirectionDown
 
case Success

case Failure
 
case Retry
 
case Start
 
case Stop
 
case Click

}

This only works on the device, not in the simulator.