3

I like to get the gyro and accelerometer data of the Apple Watch streamed to the IPhone paired app (with highest possible refresh rate). There does not seam to be an sdk for accessing the data?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
HixField
  • 3,538
  • 1
  • 28
  • 54

2 Answers2

9

Sensor Data information is now available in Watchkit for watchOS 2.0.

You could check this information in the following session which is total 30 minutes presentation.If you do not want to watch entire session, then you directly jump to the CoreMotion and HealthKit features which is in between 22-28 min:

WatchKit for watchOS 2.0 Session in WWDC 2015

Here is the implementation in WatchKit Extension, here is the reference.

import WatchKit
import Foundation
import CoreMotion

class InterfaceController: WKInterfaceController {


    @IBOutlet weak var labelX: WKInterfaceLabel!
    @IBOutlet weak var labelY: WKInterfaceLabel!
    @IBOutlet weak var labelZ: WKInterfaceLabel!
    let motionManager = CMMotionManager()


    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)

        motionManager.accelerometerUpdateInterval = 0.1
    }

    override func willActivate() {
        super.willActivate()

        if (motionManager.accelerometerAvailable == true) {
            let handler:CMAccelerometerHandler = {(data: CMAccelerometerData?, error: NSError?) -> Void in
                self.labelX.setText(String(format: "%.2f", data!.acceleration.x))
                self.labelY.setText(String(format: "%.2f", data!.acceleration.y))
                self.labelZ.setText(String(format: "%.2f", data!.acceleration.z))
            }
            motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: handler)
        }
        else {
            self.labelX.setText("not available")
            self.labelY.setText("not available")
            self.labelZ.setText("not available")
        }
    }

    override func didDeactivate() {
        super.didDeactivate()

        motionManager.stopAccelerometerUpdates()
    }
}
casillas
  • 16,351
  • 19
  • 115
  • 215
  • 1
    Thanks to quote my code: https://github.com/shu223/watchOS-2-Sampler/blob/master/watchOS2Sampler%20WatchKit%20Extension/AccelerometerInterfaceController.swift I would be glad if you introduce this link as a reference. – shu223 Aug 13 '15 at 10:54
  • 1
    as you can see in shu233's code Gyro still doesn't work. – joon Nov 24 '15 at 21:28
-3

Nope. The WatchKit SDK has no hardware access at this time.

bgilham
  • 5,909
  • 1
  • 24
  • 39