Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Not able to sendEvent() with more than one argument #96

Open
icykey opened this issue Apr 22, 2013 · 3 comments
Open

Not able to sendEvent() with more than one argument #96

icykey opened this issue Apr 22, 2013 · 3 comments

Comments

@icykey
Copy link

icykey commented Apr 22, 2013

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.

@crashbell
Copy link

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"]];

@icykey
Copy link
Author

icykey commented Jan 11, 2014

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

@mattstone
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants