Latest 2.1.0
Homepage https://github.com/abpopov/SocketCluster-ios-client
License MIT
Platforms ios 7.0, requires ARC
Dependencies SocketRocket
Authors

Native iOS client for SocketCluster http://socketcluster.io/

Notice: Client support SocketCluster v.3. Also tested on SocketCluster v.4

Setup

Use CocoaPods

pod "SocketCluster-ios-client";

Usage

Connect

[[SCSocket client] initWithHost:@«host» onPort:portNo securely:YES];   
//set delegate
[SCSocket client].delegate=self;   
//use this, if you want restore subscriptions on reconnect
[[SCSocket client] setRestoreChannels:YES];
[[SCSocket client]  connect];

channels

use SCChannel class

SCChannel* channel = [[SCChannel alloc] initWithChannelName:@"test" andDelegate:nil];

    [channel subscribeWithSuccess:^(id response) {

    } withFail:^(NSError *error, id response) {

    }];

SCChannel methods

//create channel with name and delegate
-(nonnull instancetype) initWithChannelName:(nonnull NSString*)channelName andDelegate:(nullable id /*<SCChannelDelegate>*/)delegate;
//return channel name
-(nonnull NSString*)getName;
// subscribe to channel with success and fail block
-(void)subscribeWithSuccess:(nullable void (^)(id response))success withFail:(nullable void (^)(NSError* error,id response))fail;
// unsubscribe from channel with success block
-(void)unsubscribeWithSuccess:(nullable void (^)(void))success;

SCChannelDelegate methods

//fires when some publish data to channel
-(void)SCChannel:(nonnull id/*<SCChannel>*/) channel receiveData:(nullable id)data;
//fires when server send kickOut event
-(void)SCChannel:(nonnull id/*<SCChannel>*/) channel kickOutWithMessage:(nullable id)message;

messages

use SCMessage class

[[[SCMessage alloc] initWithEventName:@«eventName» andData:@{@"data":@"test" }] send]

SCMessage methods

// init message with event name and data
-(nonnull instancetype) initWithEventName:(nonnull NSString*)eventName andData:(nullable id)data
//send message without success and fail block
//return message cid
-(NSInteger)send;
//send message with success and fail block
//return message cid
-(NSInteger)sendWithSuccess:(nullable void (^)(SCMessage* message,id response))success withFail:(nullable void (^)(SCMessage* message,id response))fail;
//send message without success and fail block to channel
//return message cid
-(NSInteger)sendToChannel:(SCChannel*)channel;
//send message with success and fail block to channel
//return message cid
-(NSInteger)sendToChannel:(SCChannel*)channel withSuccess:(nullable void (^)(SCMessage* message,id response))success withFail:(nullable void (^)(SCMessage* message,id response))fail;

additional methods of SCSocket class

// emit ‘login’ event with data and success/fail blocks
-(void)loginWithData:(nullable NSDictionary*)data withSuccess:(nullable void (^)(id response))success withFail:(nullable void (^)(id response))fail;
//subscribe to channel without success/fail blocks
-(void)subscribeToChannel:(SCChannel*)channel
//send SCMessage to SCChannel
-(NSInteger)sendMessage:(SCMessage*)message toChannel:(nullable SCChannel*)channel;
//emit event 
//this method don’t add message to queue, so if connection lost it will not resend 
-(NSInteger) emitEvent:(NSString*)event withData:(id)data

SocketClusterDelegate methods

//call after  client connect to server and #handshake event
-(void)socketClusterConnectEvent;
//call after #setAuthToken event
-(void)socketClusterAuthenticateEvent:(NSString*)token
//call every time, when client receive event from server
-(void)socketClusterReceivedEvent:(NSString *)eventName WithData:(NSDictionary *)data isStandartEvent:(BOOL)isStandartEvent;

Latest podspec

{
    "name": "SocketCluster-ios-client",
    "version": "2.1.0",
    "summary": "Native iOS client for SocketCluster http://socketcluster.io/",
    "description": "Native iOS client for SocketCluster http://socketcluster.io/.",
    "homepage": "https://github.com/abpopov/SocketCluster-ios-client",
    "license": "MIT",
    "authors": {
        "Anatoliy": "[email protected]"
    },
    "source": {
        "git": "https://github.com/abpopov/SocketCluster-ios-client.git",
        "tag": "2.1.0"
    },
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "SocketCluster-ios-client": [
            "Pod/Assets/*.png"
        ]
    },
    "dependencies": {
        "SocketRocket": []
    }
}

Pin It on Pinterest

Share This