Skip to content

Instantly share code, notes, and snippets.

@aaronbuchanan
Forked from arbarlow/gist:68b41fa7f2c5aa74e0ac
Last active August 29, 2015 14:20
Show Gist options
  • Save aaronbuchanan/5df6887f76026bb25acb to your computer and use it in GitHub Desktop.
Save aaronbuchanan/5df6887f76026bb25acb to your computer and use it in GitHub Desktop.
@implementation InterfaceController
{
SRWebSocket *_webSocket;
}
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
}
- (IBAction)didOpen {
[_webSocket send:@"1"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(500 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
[_webSocket send:@"0"];
});
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
[_webSocket close];
_webSocket = nil;
_webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:API_URL]];
_webSocket.delegate = self;
[_webSocket open];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
if (_webSocket) {
[_webSocket send:@"0"];
}
[_webSocket close];
_webSocket = nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment