startRelativeAltitudeUpdates on a Background OperationQueue

This dev tip is brought to you by the developer of MoneyPhone: Personal Expense Tracking for Android and iOS. Consistently spend less than you earn each month and get your finances under control when you start monitoring your expenses with MoneyPhone!

Doing a little hacking on my WingsuitGP app tonight so I can take it for a test flight tomorrow. The original prototype used a really ugly work-around to access altitude (pressure) data in the background, so I would like to make a note here of an excellent blog post demonstrating how to properly run altitude updates in the background on iOS: Locating a Snowboarder on a Slope
The example snippets of code I’ve found around the web regarding startRelativeAltitudeUpdates all had the updates running on OperationQueue.main, but after discovering the aforementioned mentioned blog post, it looks like it’s fairly simple to create your own OperationQueue and specify that you would like it to run in the background. I’m sure an experienced iOS developer would have been able to figure this out in 5 min., but… o well! Now I know ๐Ÿ™‚

// Code Snippet by
let queue = OperationQueue()
queue.qualityOfService = .background
queue.maxConcurrentOperationCount = OperationQueue.defaultMaxConcurrentOperationCount
let altimeter = CMAltimeter()
altimeter.startRelativeAltitudeUpdates(to: queue,
    withHandler: { data, error in //(CMAltitudeData?, Error?)
        guard error == nil else { return }
        guard let data = data else { return }
        //NOTE: process data ๐Ÿ‚!!!