-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBarometer.m
48 lines (41 loc) · 1.29 KB
/
Barometer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Barometer.m
// Barometer
//
// Created by Montana Burr on 9/23/14.
// Copyright (c) 2014 Montana. All rights reserved.
//
#import "Barometer.h"
@implementation Barometer
{
CMAltimeter *altimeter;
NSInteger elevation;
}
-(id)init
{
self = [super init];
if (self) {
altimeter = [[CMAltimeter alloc] init];
}
return self;
}
-(void)startUpdatingPressureData
{
if ([CMAltimeter isRelativeAltitudeAvailable])
{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
void(^altHandler)(CMAltitudeData *data, NSError *error) = ^(CMAltitudeData *data, NSError *error) {
if (!error) {
AirPressureValue *value = [[AirPressureValue alloc] initWithkiloPascals:[[data pressure] floatValue]];
[(NSObject *)[self delegate] performSelectorOnMainThread:@selector(dataUpdated:) withObject:value waitUntilDone:true];
}
else
{
[(NSObject *)[self delegate] performSelectorOnMainThread:@selector(pressureDataUnavailable:) withObject:error waitUntilDone:true];
}
};
[queue addOperationWithBlock:^(void) { NSLog(@"Updating altitude data."); } ];
[altimeter startRelativeAltitudeUpdatesToQueue:queue withHandler:altHandler];
}
}
@end