Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger vibration on Apple Watch OS 2?

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?

like image 356
Jiri Avatar asked Sep 02 '15 20:09

Jiri


People also ask

How do I put my Apple Watch 2 on vibrate?

Open the Settings app. Scroll down and tap Sounds & Haptics. Turn Haptic Alerts on or off. To add extra emphasis to haptic alerts, tap Prominent.

Can you make your Apple Watch vibrate constantly?

On your iPhone, in the Watch app, go to: My Watch > Sounds & Haptics: Check that the Alert Volume is towards the centre or right hand side. Check that Silent Mode is not enabled. Check that Haptic Strength is set to the middle or far right hand side of the slider.

Why won't my Apple Watch vibrate anymore?

Check Haptic Settings for Other Apps If your Apple Watch fails to vibrate for any other app-related alerts (e.g., when you receive a VIP message from Mail), open the Watch app on your iPhone, locate and tap the app, and make sure that any Haptic notifications are active.


5 Answers

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.

like image 95
LucPts Avatar answered Nov 07 '22 23:11

LucPts


In Swift 3:

WKInterfaceDevice.current().play(.success)
like image 43
Zoltan Avatar answered Nov 08 '22 00:11

Zoltan


I'm not a expert in WatchKit but I know that with Watch OS 2 you can use:

WKInterfaceDevice().playHaptic(.Notification)

The function playHaptic called on a WKInterfaceDevice instance engage the haptic engine in Apple Watch.

See more in the Apple documentation.

like image 3
Massimo Polimeni Avatar answered Nov 07 '22 22:11

Massimo Polimeni


The Correct format is

WKInterfaceDevice.currentDevice().playHaptic(.Notification)

You can easily play the notification sound on watch

like image 2
Manish Gumbal Avatar answered Nov 07 '22 23:11

Manish Gumbal


Function :

WKInterfaceDevice().playHaptic(.Notification)

Here you have : Documentation

like image 1
Onvil Avatar answered Nov 08 '22 00:11

Onvil