Skip to content

Instantly share code, notes, and snippets.

@nielsbot
Created May 31, 2015 20:15
Show Gist options
  • Save nielsbot/ba06510907886bae5ae7 to your computer and use it in GitHub Desktop.
Save nielsbot/ba06510907886bae5ae7 to your computer and use it in GitHub Desktop.
simple Core Motion sample
import CoreMotion
public class Main
{
var motionManager:CMMotionActivityManager!
let motionHandler:CMMotionActivityHandler! = { (activity:CMMotionActivity?) -> Void in
let desc = activity?.debugDescription ?? "no activity"
println("activity is \(desc)")
}
init?()
{
if !CMMotionActivityManager.isActivityAvailable() { return nil }
self.motionManager = CMMotionActivityManager()
self.motionManager.startActivityUpdatesToQueue( NSOperationQueue.mainQueue(), withHandler: self.motionHandler )
NSRunLoop.mainRunLoop().run()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment