iOS Accelerometer Example

I have downloaded the github StarterProject example. I have it building and running on iOS. It connects to my MetaMotionR and retrieves the temperature log from the device.

I would like to now modify it so that I can get real time accelerometer data from the device. I can't figure out how to do that.

I looked at the documentation and found a page talking about Swift tutorials here:

The problem is that example code doesn't look anything like the code in the downloaded example. The downloaded example self.device doesn't have a property called accelerometer.

It also doesn't use this:

    device.addObserver(self, forKeyPath: "state", options: NSKeyValueObservingOptions.New, context: nil)

Instead the downloaded sample has this:

    if let state = DeviceState.loadForDevice(device) {
        // Initialize the device

So where do I find an example of accelerometer that would work in the StarterProject example?


  • The Swift SDK just underwent major breaking changes in v3; the tutorial page currently is for the older v2 releases.

    The v3 release wraps around the same C++ library as the JavaScript and Python SDKs so the Swift code will follow the same flow as the JS / Python examples:

    You'll want to refer to the C++ documentation as well as you will be calling it from Swift:

  • Thanks Eric for the links but is it possible to get a complete example for IOS as we had before with MetaWearApiTest ( ? for accelerometer, but also gyroscope and sensorfusion (NDOF particularly as new firmware seems to improve it...)

    Personally I choose to worked with metamotion-r two years ago as some clear examples for IOS were provided with this example app.
    Without a guideline to convert our iOS code, this new firmware appears like a nightmare as we have to rewrite all our code...

    Thanks for your attention

  • I got it all working. Thanks, Eric, for the tips.

This discussion has been closed.