Skip to content

Instantly share code, notes, and snippets.

@FZambia
Last active April 6, 2017 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FZambia/44c173d6da3e0e948dc3eb784c86ec59 to your computer and use it in GitHub Desktop.
Save FZambia/44c173d6da3e0e948dc3eb784c86ec59 to your computer and use it in GitHub Desktop.
Gomobile Objective-C example
//
// ViewController.m
// CentrifugoObjectiveC
//
// Created by Alexander Emelin on 05/04/2017.
// Copyright © 2017 Alexander Emelin. All rights reserved.
//
#import "Centrifuge/Centrifuge.objc.h"
#import "ViewController.h"
@interface ViewController () <CentrifugeConnectHandler, CentrifugeDisconnectHandler, CentrifugeMessageHandler>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CentrifugeCredentials *creds = CentrifugeNewCredentials(@"42", @"1488055494", @"", @"24d0aa4d7c679e45e151d268044723d07211c6a9465d0e35ee35303d13c5eeff");
NSString *url = @"ws://localhost:8000/connection/websocket";
CentrifugeEventHandler *eventHandler = CentrifugeNewEventHandler();
[eventHandler onConnect:self];
[eventHandler onDisconnect:self];
CentrifugeClient *client = CentrifugeNew(url, creds, eventHandler, CentrifugeDefaultConfig());
NSError *error = nil;
if (![client connect:&error]) {
if (error != nil) {
NSLog(@"Error connect");
}
}
CentrifugeSubEventHandler *subEventHandler = CentrifugeNewSubEventHandler();
[subEventHandler onMessage:self];
error = nil;
[client subscribe:@"public:chat" events:subEventHandler error:&error];
if (error != nil) {
NSLog(@"Subscribe error");
}
}
- (void)onMessage:(CentrifugeSub *)p0 p1:(CentrifugeMessage *)p1 {
NSLog(@"Messsage received");
}
- (void)onConnect:(CentrifugeClient *)p0 p1:(CentrifugeConnectContext *)p1 {
NSLog(@"Connected");
}
- (void)onDisconnect:(CentrifugeClient *)p0 p1:(CentrifugeDisconnectContext *)p1 {
NSLog(@"Disconnected");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment