I'm trying to create a healthcare application and am using Core Motion's CMPedometer to obtain live step count. However, I wanted the step count to be uploaded in real time to Firebase, as well as to return this data stored in Firebase to display the Total Number of Steps the user has walked in the history of using the Healthcare App.
I've already connected Firebase to my app using Cocoapods, but unlike data that is manually created and uploaded to a database - like text messages, it seems complicated to upload the live step count obtained from the CMPedometer class.
import UIKit
import CoreMotion
import Firebase
class FirstViewController: UIViewController {
@IBOutlet weak var stepLabel: UILabel!
var myPedometer = CMPedometer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
myPedometer = CMPedometer()
myPedometer.startUpdates(from: NSDate() as Date, withHandler: { (pedometerData, error) in
if let e = error {
print(e.localizedDescription)
return
}
guard let data = pedometerData else {
return
}
let myStep = data.numberOfSteps
self.stepLabel.text = "\(myStep)"