From 479c5003bdb5f3da52b58941d6c476d290c006e4 Mon Sep 17 00:00:00 2001 From: aaa Date: Fri, 10 Oct 2014 17:04:49 +0100 Subject: [PATCH] Fixed threading in ios --- src/ios/SocketsForCordova/Classes/SocketAdapter.m | 9 ++++++++- src/ios/SocketsForCordova/Classes/SocketPlugin.m | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ios/SocketsForCordova/Classes/SocketAdapter.m b/src/ios/SocketsForCordova/Classes/SocketAdapter.m index 83fd2f2..b725d31 100644 --- a/src/ios/SocketsForCordova/Classes/SocketAdapter.m +++ b/src/ios/SocketsForCordova/Classes/SocketAdapter.m @@ -20,11 +20,18 @@ NSOutputStream *outputStream; inputStream = (__bridge NSInputStream *)readStream; [inputStream setDelegate:self]; - [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + //[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [inputStream open]; outputStream = (__bridge NSOutputStream *)writeStream; [outputStream open]; + + [self performSelectorOnMainThread:@selector(runReadLoop) withObject:nil waitUntilDone:NO]; +} + + +- (void)runReadLoop { + [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } - (void)close { diff --git a/src/ios/SocketsForCordova/Classes/SocketPlugin.m b/src/ios/SocketsForCordova/Classes/SocketPlugin.m index 1182586..d4fec0c 100644 --- a/src/ios/SocketsForCordova/Classes/SocketPlugin.m +++ b/src/ios/SocketsForCordova/Classes/SocketPlugin.m @@ -69,6 +69,7 @@ [self.commandDelegate runInBackground:^{ @try { [socket connect:host port:port]; + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];