1

I am making an apple watch app where it gets the accelerometer data from a date to another date. By using this code:

@IBAction func start() {
    WKInterfaceDevice.currentDevice().playHaptic(WKHapticType.Start)
    let startDate = NSDate()
    NSUserDefaults.standardUserDefaults().setObject(startDate, forKey: "StartDate")
}

@IBAction func stop() {
    WKInterfaceDevice.currentDevice().playHaptic(WKHapticType.Stop)
    let endDate = NSDate()
    let startDate = NSUserDefaults.standardUserDefaults().objectForKey("StartDate") as! NSDate
    printData(startDate, endDate: endDate)
}

Then when I got to export the data using the function printData() which this is the code for that function

func printData(startDate: NSDate, endDate: NSDate) {
    let recorder = CMSensorRecorder()
    let list: CMSensorDataList = recorder.accelerometerDataFromDate(startDate, toDate: endDate)!

    for (index, data) in list.enumerate() {
        print(index, data)
    }
}

For the enumeration I have an extension and here is the code for the extension:

extension CMSensorDataList: SequenceType {
    public func generate() -> NSFastGenerator {
       return NSFastGenerator(self)
    }
}

When I press the stop button the app crashes. I got all of my code from this question(Swift watchOS 2 - CMSensorDataList) but it doesn't work on my device. Does anyone know what is happening?

Community
  • 1
  • 1
Loanb222
  • 841
  • 1
  • 11
  • 29

1 Answers1

0

You need an entry for NSMotionUsageDescription in your Info.plist file. If you crash while attached to Xcode, it should give you this information.

Victor Engel
  • 2,037
  • 2
  • 25
  • 46