Recording accelerometer data and share
<p>I am working on getting accelerometer data when the device is in our hand and moved. I have done a working program for getting accelerometer motion and rotation data. Next is, I want to record it and share via email. I was reading about <strong>recordAccelerometerForDuration</strong>, but I don't know how to use this for recording accelerometer data and share it via email. I could see apple developer help from this link <a href="http://CMSensorRecorder_class" rel="nofollow">https://developer.apple.com/library/ios/documentation/CoreMotion/Reference/CMSensorRecorder_class/</a></p>

<p>Could someone share some sample how to record the value and share in mail to achieve both?</p>

<p><strong>UPDATE</strong></p>

<p>I prepared a sample code for recording accelerometer like below,</p>

<pre><code>@IBAction func startRecorderAction() {

    guard CMSensorRecorder.isAccelerometerRecordingAvailable() else {

        print("Accelerometer data recording is not available")

        return
    }

    let recorder = CMSensorRecorder()
    let duration = 3.0

    if CMSensorRecorder.isAuthorizedForRecording(){
        print("SensorRecorder authorized")
    }else{
        print("SensorRecorder not authorized")
    }

    recorder.recordAccelerometerForDuration(duration)
    NSOperationQueue().addOperationWithBlock{[unowned recorder] in

        NSThread.sleepForTimeInterval(duration)

        let now = NSDate()

        let past = now.dateByAddingTimeInterval(-(duration))

        let data = recorder.accelerometerDataFromDate(past, toDate: now)

        let accelerationData: [CMAcceleration] = data!.map {

            //every $0 is CMRecordedAccelerometerData

            $0.acceleration

        }

        print(accelerationData)

    }
}
</code></pre>

<p>When I run the app, it says "Accelerometer data recording is not available" . But I am using iPhone 6 and iOS 9.3.1 version. then why this is showing error as accelerometer recording is not available and how to get rid out this?
Could someone help please?</p>