diff --git a/ios/TcpSocketClient.m b/ios/TcpSocketClient.m index ad52d6c..b636c65 100644 --- a/ios/TcpSocketClient.m +++ b/ios/TcpSocketClient.m @@ -66,6 +66,7 @@ @interface TcpSocketClient () { long _sendTag; SecTrustRef _peerTrust; SecIdentityRef _clientIdentity; + NSDictionary *_tlsOptionsPending; } - (id)initWithClientId:(NSNumber *)clientID @@ -163,7 +164,7 @@ - (BOOL)connect:(NSString *)host error:error]; } if (result && tlsOptions) { - [self startTLS:tlsOptions]; + _tlsOptionsPending = [tlsOptions copy]; // Save for later } return result; } @@ -571,9 +572,15 @@ - (void)socket:(GCDAsyncSocket *)sock return; } - // Show up if SSL handsake is done + // Show up if SSL handshake is done if (!_tls) { - [_clientDelegate onConnect:self]; + if (_tlsOptionsPending) { + [self startTLS:_tlsOptionsPending]; + _tlsOptionsPending = nil; + } else { + [_clientDelegate onConnect:self]; + _connecting = false; + } } [sock readDataWithTimeout:-1 tag:_id.longValue]; }