Giter Club home page Giter Club logo

watchshaker's Introduction

WatchShaker

Simple motion detector for ⌚️ (watchOS) shake gesture.

Swift Version Platform github workflow DOI License


WatchShaker is a watchOS helper to get your ⌚️ shake movements

Requirements

  • watchOS 6.0+
  • Xcode 14.0+

Installation

Swift Package Manager

Once you have your Swift package set up, adding WatchShaker as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/ezefranca/WatchShaker.git")
]

Manually

  1. Download and drop WatchShaker folder in your project to your watch target.
  2. Congratulations!

Usage example

@StateObject style

import SwiftUI
import WatchShaker

struct ContentView: View {
    
    @StateObject var shaker:WatchShaker = WatchShaker(shakeSensibility: .shakeSensibilityNormal, delay: 0.2)
    
    var body: some View {
        VStack {
            if shaker.isShakerAvailable {
                Text("I'm shook! ⌚️⌚️⌚️")
                Text("\(shaker.shake.sensibility)")
                Text("\(shaker.shake.direction)")
            }
        }
    }
}

Closure Style

import WatchKit
import Foundation
import WatchShaker

class InterfaceController: WKInterfaceController {
    
    var shaker:WatchShaker = WatchShaker(shakeSensibility: .shakeSensibilityNormal, delay: 0.2)
    
    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
    }
    
    override func willActivate() {
        super.willActivate()
        
        shaker.start()
        
        shaker.startWatchShakerUpdates = { shakeSensibility, error in
            
            guard error == nil else
            {
                print(error?.localizedDescription)
                return
            }
            print("I'm shook! ⌚️⌚️⌚️")
        }
    }
    
    override func didDeactivate() {
        super.didDeactivate()
        shaker.stop()
    }

}

Delegate Style

import WatchKit
import Foundation


class InterfaceController: WKInterfaceController {

    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        // Configure interface objects here.
    }

    var shaker:WatchShaker = WatchShaker(shakeSensibility: .shakeSensibilityNormal, delay: 0.2)

    override func willActivate() {

        super.willActivate()
        shaker.delegate = self
        shaker.start()
    }

    override func didDeactivate() {

        super.didDeactivate()
        shaker.stop()

    }

}

extension InterfaceController: WatchShakerDelegate
{
    func watchShaker(_ watchShaker: WatchShaker, didShakeWith sensibility: ShakeSensibility) {
        print("I'm shook! ⌚️⌚️⌚️")
    }

    func watchShaker(_ watchShaker: WatchShaker, didFailWith error: Error) {
        print(error.localizedDescription)
    }
}

Optional Directions

If you interested you can get the direction of the shake on the didShakeWith method.

func watchShaker(_ watchShaker: WatchShaker, didShakeWith sensibility: ShakeSensibility, 
                     direction: ShakeDirection) {
    print("I'm shook! ⌚️⌚️⌚️ \(direction)")
}

ShakeDirection is a simple enum who gives you up, down, left or right direction. The image bellow is the way used to determine what is each direction.


This gentleman bellow for example, is clearly doing a shake with ShakeDirection.shakeDirectionRight 😂


Contribute

We would love for you to contribute to WatchShaker, check the LICENSE file for more info.

Meta

Docs: Here

Ezequiel França – @ezefranca and all awesome Contributors

Distributed under the MIT license. See LICENSE for more information.

watchshaker's People

Contributors

digitaldaring avatar ezefranca avatar ghv avatar lorenzhk avatar makhocheung avatar markohlebar avatar sky-ezequielsantos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

watchshaker's Issues

Shake gesture not recognized

I implemented this and was working yesterday, now I am getting the following in the debugger: "[Gyro] Manually set gyro-interrupt-calibration to 800"

Two copies of WatchShaker source code

Can we remove the copy in WatchShaker WatchKit Extension/WatchShaker.swift and have the project reference the copy in ./Pod/Classes/WatchShaker.swift?

Background Support

Can we have a back background support for this?

If, yes that will be greate!!

Thank You

Alternate license?

First of all, thanks so much for this. It looks absolutely lovely!

However: while I'm interested in using it for a project, I'm concerned about its use of the GPL. Specifically, it's widely believed that the terms of the GPL are generally incompatible with the iOS App Store terms of service (there are some exceptions and caveats to that, but they don't really apply here).

Is there any chance you'd be willing to relicense this library under a more permissive license, such as the MIT or BSD license? I fully understand if not, and if you don't feel comfortable licensing this under a non-copyleft license, but as it stands I don't think there is any way for anyone to use your library with their Apple Watch app and also release it on the App Store, even if their app is also GPL.

(If this isn't something you're too familiar with, happy to explain more or answer questions, with the caveat that I am not a lawyer).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.