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?
Asked
Active
Viewed 4,017 times
2 Answers
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
-
1Thanks 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
-
1as 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
-
Well that is a shame. But the hw specs do say it contains gyro and accelerometer I believe... Strange then that the api does not exist... Yet? – HixField Apr 04 '15 at 18:37
-
@HixField It's been speculated that this functionality is coming in the next version of WatchKit; right now, they're trying to keep things simple to go easy on battery life. – AstroCB Apr 05 '15 at 03:57
-
@AstroCB I hope :-) it would not make much sense to include the hw witout sw support ... – HixField Apr 05 '15 at 06:10
-
-