WatchShaker

WatchShaker is a lightweight library for detecting shakes and wrist movements on Apple Watch. This library offers a simple and efficient way to detect common user gestures on the watch.

Features

  • Shake detection: Detect when the user shakes their Apple Watch.
  • Wrist flick detection: Detect when the user flicks their wrist.
  • Customizable sensitivity: Adjust the sensitivity level for detecting shakes and wrist flicks.
  • Delegate methods: Use delegate methods to receive notifications for shake and flick events.
  • Support for complications: Enable WatchShaker to work with complications on Apple Watch.
  • Easy integration: Seamlessly integrate WatchShaker into your existing Apple Watch apps.

Installation

To install WatchShaker, follow these steps:

  1. Download the WatchShaker framework from the official GitHub repository: https://github.com/your-link-goes-here
  2. Add the WatchShaker framework to your Xcode project.
  3. Import the WatchShaker module in your Swift file:
import WatchShaker
  1. Set up the WatchShaker class as shown in the example below:
import WatchKit

// Your Watch Extension Delegate
class ExtensionDelegate: NSObject, WKExtensionDelegate {
    var watchShaker: WatchShaker?

    func applicationDidFinishLaunching() {
        watchShaker = WatchShaker(delegate: self)
        watchShaker?.start()
    }
    
    // Implement the delegate methods
}

// Your Shake Delegate
extension ExtensionDelegate: WatchShakerDelegate {
    func watchShakerDidShake(device: WKInterfaceDevice) {
        // Action to perform on shake event
    }
    
    func watchShakerDidFlick(device: WKInterfaceDevice) {
        // Action to perform on wrist flick event
    }
}

Note: Make sure to implement the shake and flick delegate methods in your code to receive the corresponding events.

Usage

Using WatchShaker is straightforward. Here’s an example of how you can use it in your Apple Watch app:

import WatchShaker

class InterfaceController: WKInterfaceController {
    var watchShaker: WatchShaker?
    
    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        watchShaker = WatchShaker(delegate: self)
        watchShaker?.start()
    }
    
    // Implement the delegate methods
}

extension InterfaceController: WatchShakerDelegate {
    func watchShakerDidShake(device: WKInterfaceDevice) {
        // Action to perform on shake event
    }
    
    func watchShakerDidFlick(device: WKInterfaceDevice) {
        // Action to perform on wrist flick event
    }
}

Customization

WatchShaker allows customization of sensitivity levels for shake and flick events. To customize the sensitivity, use the following methods:

import WatchShaker

class InterfaceController: WKInterfaceController {
    var watchShaker: WatchShaker?
    
    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        
        // Set custom sensitivity levels
        WatchShaker.shared.shakeThreshold = 2.5
        WatchShaker.shared.flickThreshold = 2.0
        
        // Start WatchShaker as usual
        watchShaker = WatchShaker(delegate: self)
        watchShaker?.start()
    }
    
    // Implement the delegate methods
}

Complication Support

WatchShaker can be used alongside complications in your Apple Watch app. To enable complications support, follow these steps:

  1. In your project target, go to the “Capabilities” tab.
  2. Enable the “Background Modes” capability.
  3. Check the “Audio, AirPlay and Picture in Picture” checkbox.

Note: Enabling background modes allows WatchShaker to run in the background and continue detecting shakes and flicks even when the app is in the background.

Conclusion

WatchShaker simplifies shake and wrist flick detection on Apple Watch, providing an efficient way to add gesture-based interactions in your watchOS apps. With its customizable sensitivity levels and delegate methods, you can easily integrate WatchShaker into your projects. Don’t miss the opportunity to enhance user experiences on Apple Watch with WatchShaker!