Watch Kit: is it possible to vibrate watch program

2019-03-17 13:34发布

问题:

Is it possible to vibrate watch while Watch Extension is running? We can do it on iOS in this way (force iPhone to vibrate):

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

I hope there is something similar on WatchKit.

Update: I have added issue to Apple radar and recieved the answer:

Engineering has determined that your bug report (20019274) is a duplicate of another issue (19025053) and will be closed.

19025053 is still open.

Update 2: AudioServicesPlayAlertSound() not working on watch simulator with any sound ID. Seems like function is not supported.

回答1:

You can now ask the Watch to vibrate if you target watchOS 2.0

To do this all you need to do is call playHaptic on a WKInterfaceDevice instance with any WKHapticType. In the example below it will play the notification haptic.

Swift 3

WKInterfaceDevice.current().play(.notification)

Objective-C

[[WKInterfaceDevice currentDevice] playHaptic:WKHapticTypeNotification];

You can further read the Apple WKInterfaceDevice Documentation



回答2:

That's a great question, but unfortunately the answer is no. WatchKit doesn't have any APIs available to control haptic feedback. If you would really like to see this feature supported, I'd suggest you file a radar as a feature request.



回答3:

This is the answer in objective-c after watchOS 2

[[WKInterfaceDevice currentDevice] playHaptic:WKHapticTypeNotification];


回答4:

With WatchKit, you have to remember that your code runs on the iPhone and not on the watch. Therefore, AudioServicesPlaySystemSound call from a WatchKit extension would run on the iPhone, not on the watch. It will make the iPhone vibrate.