From 6446c6fbe02730b6c3e40538f8dd01cc73b71ca7 Mon Sep 17 00:00:00 2001 From: Frederic Jacobs Date: Thu, 27 Nov 2014 11:48:04 +0100 Subject: [PATCH] Socket Management --- Signal/src/AppDelegate.m | 5 +++-- .../Network/WebSockets/TSSocketManager.m | 14 ++++++++++++-- Signal/src/util/protocols/PreKeyBundle+jsonDict.m | 1 - 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 48288b41f..7ed9c888c 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -208,6 +208,7 @@ } -(void) applicationDidBecomeActive:(UIApplication *)application { + [TSSocketManager becomeActive]; [AppAudioManager.sharedInstance awake]; // Hacky way to clear notification center after processed push @@ -231,8 +232,8 @@ completionHandler(); } -- (void)applicationWillResignActive:(UIApplication *)application{ - [self protectScreen]; +- (void)applicationDidEnterBackground:(UIApplication *)application{ + [TSSocketManager resignActivity]; } - (void)prepareScreenshotProtection{ diff --git a/Signal/src/textsecure/Network/WebSockets/TSSocketManager.m b/Signal/src/textsecure/Network/WebSockets/TSSocketManager.m index 2fdefa197..123c7bf65 100644 --- a/Signal/src/textsecure/Network/WebSockets/TSSocketManager.m +++ b/Signal/src/textsecure/Network/WebSockets/TSSocketManager.m @@ -163,7 +163,12 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification"; [message setResponse:response.build]; [message setType:WebSocketMessageTypeResponse]; - [self.websocket send:message.build.data]; + @try { + [self.websocket send:message.build.data]; + } + @catch (NSException *exception) { + DDLogWarn(@"Caught exception while trying to write on the socket %@", exception.debugDescription); + } } - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { @@ -174,7 +179,12 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification"; } - (void)webSocketHeartBeat { - [self.websocket sendPing:nil]; + @try { + [self.websocket sendPing:nil]; + } + @catch (NSException *exception) { + DDLogWarn(@"Caught exception while trying to write on the socket %@", exception.debugDescription); + } } - (NSString*)webSocketAuthenticationString{ diff --git a/Signal/src/util/protocols/PreKeyBundle+jsonDict.m b/Signal/src/util/protocols/PreKeyBundle+jsonDict.m index 653c73aa3..c79234839 100644 --- a/Signal/src/util/protocols/PreKeyBundle+jsonDict.m +++ b/Signal/src/util/protocols/PreKeyBundle+jsonDict.m @@ -23,7 +23,6 @@ } NSData *identityKey = [NSData dataFromBase64String:identityKeyString]; - NSLog(@"IDentityKey %@", identityKey); for (NSDictionary *deviceDict in devicesArray) { NSNumber *registrationIdString = [deviceDict objectForKey:@"registrationId"];