EMBroadcastViewController.m
1.94 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// EMBroadcastViewController.m
// BroadcastExample
//
// Created by Dexter Weiss on 12/17/13.
// Copyright (c) 2013 Emmoco. All rights reserved.
//
#import "EMBroadcastViewController.h"
#import "EMFramework.h"
@interface EMBroadcastViewController () {
IBOutlet UILabel *codeLabel;
IBOutlet UILabel *firstDataField;
IBOutlet UILabel *secondDataField;
}
@property (nonatomic, strong) EMDeviceBasicDescription *device;
@end
@implementation EMBroadcastViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[EMConnectionListManager sharedManager] addObserver:self forKeyPath:@"devices" options:0 context:NULL];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == [EMConnectionListManager sharedManager]) {
if ([keyPath isEqualToString:@"devices"]) {
NSArray *devices = [[EMConnectionListManager sharedManager] devices];
[self setDevice:[devices lastObject]];
}
}
}
-(void)setDevice:(EMDeviceBasicDescription *)device {
[self willChangeValueForKey:@"device"];
_device = device;
[self didChangeValueForKey:@"device"];
[self _updateInterfaceForDevice];
}
-(void)_updateInterfaceForDevice {
NSDictionary *broadcastInfo = [[self device] advertiseObject];
NSString *code = [broadcastInfo objectForKey:@"c"];
NSArray *values = [broadcastInfo objectForKey:@"d"];
NSNumber *first = [values firstObject];
NSNumber *second = [values lastObject];
[codeLabel setText:code];
[firstDataField setText:[NSString stringWithFormat:@"%0.1f", [first floatValue]]];
[secondDataField setText:[NSString stringWithFormat:@"%0.1f", [second floatValue]]];
}
@end