Last active
June 25, 2018 23:56
-
-
Save tfrank64/096cdb916f340c740a95 to your computer and use it in GitHub Desktop.
Retrieving data for relative altitude and air pressure with CMAltimeter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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