socket.IO-objc icon indicating copy to clipboard operation
socket.IO-objc copied to clipboard

Not able to sendEvent() with more than one argument

Open icykey opened this issue 12 years ago • 3 comments

I am trying to pass in more than one argument in the sendEvent function.

- (void) sendEvent:(NSString *)eventName withData:(NSDictionary *)data;

for example:

/namesspace:{"args":["arg1","arg2"],"name":"eventname"}

The current api does not seem to support more than one argument.

Socket.IO.m line 200:

[dict setObject:[NSArray arrayWithObject:data] forKey:@"args"];

This will always create an array of one object, even if pass in an array.

icykey avatar Apr 22 '13 02:04 icykey

I changed method

- (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(SocketIOCallback)function

to:

- (void) sendEvent:(NSString *)eventName withData:(NSArray*)data andAcknowledge:(SocketIOCallback)function
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:eventName forKey:@"name"];

    // do not require arguments
    if (data != nil) {
        [dict setObject:data forKey:@"args"];
    }

    SocketIOPacket *packet = [[SocketIOPacket alloc] initWithType:@"event"];
    packet.data = [SocketIOJSONSerialization JSONStringFromObject:dict error:nil];
    packet.pId = [self addAcknowledge:function];
    if (function) {
        packet.ack = @"data";
    }
    [self send:packet];
}

And it worked with

[socketIO sendEvent:@"event_name" withData:@[@"param1", @"param2"]];

crashbell avatar May 04 '13 14:05 crashbell

Yes, the above change will work. Can we consider merge this change in? thanks.

icykey avatar Jan 11 '14 00:01 icykey

worked for me.. also should..

  • (void) sendEvent:(NSString *)eventName withData:(id)data {

also be changed to..

  • (void) sendEvent:(NSString *)eventName withData:(NSArray *)data {

as well?

mattstone avatar Jan 23 '14 07:01 mattstone