MegaBits / SIOSocket

Realtime iOS application framework (client) http://socket.io
MIT License
494 stars 80 forks source link

Emit work on explorer not in iOS 8 #46

Open josefrm opened 9 years ago

josefrm commented 9 years ago

Hello there, im having some issue there if i open the explorer all of the emit methods works like a charm, but in iOS not.

Any idea why is that happening, some of code here:

Server:

io.on('connection', function(socket) { ClientsArray.push(new function () { this.userid = ""; this.socketid = socket.id; });

    socket.on('disconnect', function ()
    {
        for (var i = 0; i < ClientsArray.length; i++)
        {
            if (ClientsArray[i].socketid == socket.id)
            {
                ClientsArray.splice(i, 1);
                break;
            }
        }
        console.log(ClientsArray);

    });
    socket.on('chat message', function (msg)
    {
        var Ms = msg;
        console.log(msg);
        try
        {
                var arr = msg.split(";-:-;");
                var toSocketID;
                for (var i = 0; i < ClientsArray.length; i++) {
                    if (ClientsArray[i].userid.toString() == arr[1]) {
                        toSocketID = ClientsArray[i].socketid;
                        break;
                    }
                }
                io.sockets.connected[toSocketID].emit('chat message', msg);
                socket.emit('chat message', msg);
        }
        catch (err)
        {
            socket.emit('chat message', msg);

        }
    });

socket.on('id cliente', function (msg) {
    try {

        for (var i = 0; i < ClientsArray.length; i++) {
            if (ClientsArray[i].socketid.toString() == socket.id.toString()) {
                ClientsArray[i].userid = msg;
                break;
            }
        }
        socket.emit('done');
    }
    catch(err)
    {
        console.log(err);
    }
});

});

Objective C: +(ConexionSocket)sharedModel { static ConexionSocket ConexionCompartida = nil; if(!ConexionCompartida) ConexionCompartida = [[ConexionSocket alloc] init]; return ConexionCompartida; }

-(void)IniciarConexion { [SIOSocket socketWithHost: @"http://104.236.96.130:9000/" response: ^(SIOSocket *socket) { SocketS = socket; id _c = cliente; SocketS.onConnect = ^() { [_c OnSocketConnection]; };

         SocketS.onDisconnect= ^()
         {
             [_c OnSocketDisconnect];
         };
         SocketS.onError = ^(NSDictionary* D)
         {
         };
         [SocketS on:@"chat message" callback:^(SIOParameterArray *args)
          {
               NSArray *array = [args.firstObject componentsSeparatedByString:@";-:-;"];
               Mensajes *MSJ = [[Mensajes alloc] init];
               MSJ.IdEmisor = array.firstObject;
               MSJ.IdReceptor = [array objectAtIndex:1];
               MSJ.Mensaje = array.lastObject;
               [cliente OnMensajeRecibido:MSJ];
          }];
         [SocketS on:@"done" callback:^(SIOParameterArray *args)
          {
              NSLog(@"Here");
          }];
     }];

}

-(void)enviarMensaje: (NSString)mensaje MensajeTraducido: (NSString)mensajeTraducido To:(id)to From:(id)from { [SocketS emit:@"chat message" args:@[[NSString stringWithFormat:@"%@;-:-;%@;-:-;%@;-:-;%@",from, to,mensaje, mensajeTraducido]]]; }

-(void)enviarmensajeConfirmacion: (id)idUsuario { @try { NSArray Arr = [NSArray arrayWithObjects:idUsuario, nil]; [SocketS emit:@"id cliente" args:Arr]; } @catch (NSException exception) { NSLog(@"Error %@", exception); } @finally {
} }

josefrm commented 9 years ago

Note i've already changed the dispatcher on #16 but cannot emit the message (just 1 emit works) working iOS 8

What i have is 1 emit to assign the user id to socket id (this is working) and 1 emit to send the message to a specific user (this is not)

And both work perfectly in server.

, thanks

anuradhavasudeva commented 9 years ago

On iOS8 - My app has become dead after updating to latest SIOSocket!! Neither am I able to send emit nor am I able to receive server call back. Old version had its own issues. Some times the client calls weren't reaching the server and vice versa due to continuous connect and disconnect cycles. Has any one implemented apps successfully on iOS using SIOSocket? Need help...

waleedmahmood commented 9 years ago

@anuradhavasudeva Have you been able to resolve it? In my case, UI get halted. No further interaction is possible except to kill the app and re-run. :(

josefrm commented 9 years ago

I solved it, the problem is we trying to dispatch the events to the main queue the #16 explains how to fix it