#import "DUREXAppViewController.h" #import "EMFramework.h" @interface DUREXAppViewController () { IBOutlet UIActivityIndicatorView *_activityIndicator; NSTimer *_writeTimer; } @end @implementation DUREXAppViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; [_activityIndicator setHidden:YES]; [self setTitle:[[[EMConnectionManager sharedManager] connectedDevice] name]]; [[EMConnectionManager sharedManager] readResource:@"data" onSuccess:^(id readValue) { [[self valueLabel] setText:[NSString stringWithFormat:@"%d", [readValue intValue]]]; [[self valueSlider] setValue:[readValue floatValue]]; } onFail:^(NSError *error) { } ]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotification:) name:kEMConnectionDidReceiveIndicatorNotificationName object:nil]; [[EMConnectionManager sharedManager] addObserver:self forKeyPath:@"connectionState" options:0 context:NULL]; } -(void)didReceiveNotification:(NSNotification*) notification { id notificationValue = [[notification userInfo] objectForKey:kEMIndicatorResourceValueKey]; NSString *resourceName = [[notification userInfo] objectForKey:kEMIndicatorNameKey]; NSString *resourceValue = [notificationValue stringValue]; } -(void)dealloc { [[EMConnectionManager sharedManager] removeObserver:self forKeyPath:@"connectionState"]; } -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (object == [EMConnectionManager sharedManager]) { if ([keyPath isEqualToString:@"connectionState"]) { if ([[EMConnectionManager sharedManager] connectionState] == EMConnectionStateDisrupted) { [[self navigationController] popToRootViewControllerAnimated:YES]; } } } } -(NSString*) readMessage { } -(Boolean) writeMessage: (NSString*) message { __block Boolean status = FALSE; [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithFloat:[[self valueSlider] value]] toResource:@"data" onSuccess:^ { status = TRUE; } onFail:^(NSError *error) { NSLog(@"%@",error); status = FALSE; } ]; if(status != FALSE) { [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithFloat:[[self valueSlider] value]] toResource:@"data" onSuccess:^ { status = TRUE; } onFail:^(NSError *error) { NSLog(@"%@",error); status = FALSE; } ]; if(status != FALSE) { [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithFloat:[[self valueSlider] value]] toResource:@"data" onSuccess:^ { status = TRUE; } onFail:^(NSError *error) { NSLog(@"%@",error); status = FALSE; } ]; if(status != FALSE) { [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithFloat:[[self valueSlider] value]] toResource:@"data" onSuccess:^ { status = TRUE; } onFail:^(NSError *error) { NSLog(@"%@",error); status = FALSE; } ]; } } } return status; } #pragma mark - Interface actions @end