Skip to content

Instantly share code, notes, and snippets.

@tfrank64
Last active June 25, 2018 23:56
Show Gist options
  • Save tfrank64/096cdb916f340c740a95 to your computer and use it in GitHub Desktop.
Save tfrank64/096cdb916f340c740a95 to your computer and use it in GitHub Desktop.
Retrieving data for relative altitude and air pressure with CMAltimeter
//
// AltitudeViewController.swift
// Altitudes
//
// Created by Taylor Franklin on 10/22/14.
//
import UIKit
import CoreMotion
class AltitudeViewController: UIViewController {
@IBOutlet weak var altitudeLabel: UILabel!
let altimeter = CMAltimeter()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func start(sender: AnyObject) {
if CMAltimeter.isRelativeAltitudeAvailable() {
altimeter.startRelativeAltitudeUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: { data, error in
if (error == nil) {
println("Relative Altitude: \(data.relativeAltitude)")
println("Pressure: \(data.pressure)")
}
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment