myBeat/WHS-2-iOS — pull request #4 by aogilvie (2014-07-16 09:30:12+00:00)
Title: added NSNotifications for outside classes

Allow other classes to get notifications. For example:

```
- (void)viewDidLoad {
[super viewDidLoad];
// Attach notification controllers

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"MyBeatDidConnectPeripheral"
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"MyBeatDidDisconnectPeripheral"
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"MyBeatDidUpdateState"
object:nil];
}

- (void)receiveTestNotification:(NSNotification *)notification {

if ([[notification name] isEqualToString:@"MyBeatDidConnectPeripheral"]) {

NSLog (@"Successfully received the MyBeatDidConnectPeripheral notification!");
NSDictionary *userInfo = notification.userInfo;
CBPeripheral *myPeripheral = [userInfo objectForKey:@"peripheral"];
NSLog(@"peripheral id: %@", [myPeripheral UUID]);

} else if ([[notification name] isEqualToString:@"MyBeatDidDisconnectPeripheral"]) {

NSLog (@"Successfully received the MyBeatDidDisconnectPeripheral notification!");
NSDictionary *userInfo = notification.userInfo;
CBPeripheral *myPeripheral = [userInfo objectForKey:@"peripheral"];
NSLog(@"peripheral id: %@", [myPeripheral UUID]);

} else if ([[notification name] isEqualToString:@"MyBeatDidUpdateState"]) {

NSLog (@"Successfully received the MyBeatDidUpdateState notification!");
NSDictionary *userInfo = notification.userInfo;
CBCentralManagerState state = (CBCentralManagerState)[userInfo objectForKey:@"state"];
switch (state) {
case CBCentralManagerStatePoweredOff:
NSLog(@"CBCentralManagerStatePoweredOff");
break;
case CBCentralManagerStatePoweredOn:
NSLog(@"CBCentralManagerStatePoweredOn");
break;
case CBCentralManagerStateResetting:
NSLog(@"CBCentralManagerStateResetting");
break;
case CBCentralManagerStateUnauthorized:
NSLog(@"CBCentralManagerStateUnauthorized");
break;
case CBCentralManagerStateUnknown:
NSLog(@"CBCentralManagerStateUnknown");
break;
case CBCentralManagerStateUnsupported:
NSLog(@"CBCentralManagerStateUnsupported");
break;
}
}
}
```