objective-cxcodehaptic-feedback

How do you make a haptic play on the apple watch using Objective-C code


How do you make a haptic play on the apple watch when you press a button using Objective-C and Xcode.


Solution

  • Objective-C:

    [[WKInterfaceDevice currentDevice] playHaptic:WKHapticType.Success]
    

    Swift:

    WKInterfaceDevice.currentDevice().playHaptic(.Success)
    

    Types of Haptic you can play:

    WKHapticType.Notification,
    WKHapticType.DirectionUp,
    WKHapticType.DirectionDown,
    WKHapticType.Success,
    WKHapticType.Failure,
    WKHapticType.Retry,
    WKHapticType.Start,
    WKHapticType.Stop,
    WKHapticType.Click 
    

    Documentation: https://developer.apple.com/library/prerelease/watchos/documentation/WatchKit/Reference/WKInterfaceDevice_class/index.html#//apple_ref/occ/cl/WKInterfaceDevice