Skip to content

Instantly share code, notes, and snippets.

@arbarlow
Created April 28, 2015 10:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arbarlow/68b41fa7f2c5aa74e0ac to your computer and use it in GitHub Desktop.
Save arbarlow/68b41fa7f2c5aa74e0ac 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
@prasadgau
Copy link

Hi, I am trying to use socket in watch kit but i am not able to get any socket which is supported to iWatch OS. But here it was mentioned here to support the iWatch OS. Can you provide the entire library which will support to iWatch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment