Latest 1.0.0
Homepage https://github.com/Antondomashnev/socket.IO-Blocks
License MIT
Platforms ios 5.0, requires ARC
Dependencies socket.IO
Authors

README

Category on socket.IO-objc to use block callbacks instead of delegate callbacks.

Adding SocketIO+Blocks to your project

From CocoaPods

Add pod 'SocketIOBlocks' to your Podfile.

Source files

Another way to add the SocketIO+Blocks to your project is to directly add the source files and resources to your project.

  1. Download the latest code version or add the repository as a git submodule to your git-tracked project.
  2. Open your project in Xcode, than drag and drop SocketIO+Blocks.h and SocketIO+Blocks.m files onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
  3. Include SocketIO+Blocks wherever you need it with #import "SocketIO+Blocks.h".

Usage

To connect to your host simply write

SocketIO *socketIO = [[SocketIO alloc] initWithDelegate:nil];
[socketIO connectToHost:@"localhost" onPort:3000 withCallback:^(SocketIO *socketIO, NSError *error){
    NSLog(@"Socket %@ did connect with error %@", socket, error);
}];

If you need additional parameters you could use another methods

- (void)connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withCallback:(void (^)(SocketIO *, NSError *))callback;
- (void)connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint withCallback:(void (^)(SocketIO *, NSError *))callback;

A delegate methods which response on error has been replaced by two methods. Key uses for support multiple error handlers

- (void)addErrorHandler:(void (^)(SocketIO *, NSError *))handler forKey:(NSString *)key;
- (void)removeErrorHandlerForKey:(NSString *)key

To handle received messages you can add handler for specific key too

- (void)addMessageHandler:(void (^)(SocketIO *, SocketIOPacket *))handler forKey:(NSString *)key;

If you no longer need message handler you can simply remove it from socket

- (void)removeMessageHandlerForKey:(NSString *)key;

The same logic applies for handle events and JSON objects.

License

(The MIT License)

Copyright (c) 2013 Anton Domashnev. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Latest podspec

{
    "name": "SocketIOBlocks",
    "version": "1.0.0",
    "summary": "Category on socket.IO-objc to use block callbacks instead of delegate callbacks.",
    "homepage": "https://github.com/Antondomashnev/socket.IO-Blocks",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Anton Domashnev": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Antondomashnev/socket.IO-Blocks.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "5.0"
    },
    "requires_arc": true,
    "source_files": "*.{h,m}",
    "dependencies": {
        "socket.IO": []
    }
}

Pin It on Pinterest

Share This