diff options
author | siqi <me@siqi.fr> | 2013-07-09 08:39:50 +0200 |
---|---|---|
committer | siqi <me@siqi.fr> | 2013-07-10 10:48:00 +0200 |
commit | 6c9db5b3cb4ee900a5d91554efa3835ca8b973c7 (patch) | |
tree | 2543083b018a0e9179b34f578a428b927901f296 /ios | |
parent | 9487b7130609c85ccd9c6ece331bb31e3be68a51 (diff) |
bug fixes on server connection
Change-Id: Ica940b85cad51dc156ccd5879eaf404dd0ea12d5
Diffstat (limited to 'ios')
-rw-r--r-- | ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate | bin | 48996 -> 50945 bytes | |||
-rw-r--r-- | ios/iosremote/iosremote/Communication/Client.m | 41 | ||||
-rw-r--r-- | ios/iosremote/iosremote/serverList_vc.m | 4 | ||||
-rw-r--r-- | ios/iosremote/iosremote/slideShowSwipeInList.m | 3 |
4 files changed, 27 insertions, 21 deletions
diff --git a/ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate b/ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate Binary files differindex 13fb9f55ebeb..b49a1f04ffc3 100644 --- a/ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate +++ b/ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate diff --git a/ios/iosremote/iosremote/Communication/Client.m b/ios/iosremote/iosremote/Communication/Client.m index c3cbb935fe11..42bcd8b0f0b7 100644 --- a/ios/iosremote/iosremote/Communication/Client.m +++ b/ios/iosremote/iosremote/Communication/Client.m @@ -63,9 +63,9 @@ dispatch_queue_t backgroundQueue; - (void)startConnectionTimeoutTimer { [self stopConnectionTimeoutTimer]; // Or make sure any existing timer is stopped before this method is called - + NSTimeInterval interval = 3.0; // Measured in seconds, is a double - + self.connectionTimeoutTimer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(handleConnectionTimeout) @@ -99,17 +99,17 @@ dispatch_queue_t backgroundQueue; { // Look up if there is already a pin code for this client. NSUserDefaults * userDefaluts = [NSUserDefaults standardUserDefaults]; - + if(!userDefaluts) NSLog(@"userDefaults nil"); NSInteger newPin = [userDefaluts integerForKey:self.name]; - + // If not, generate one. if (!newPin) { newPin = arc4random() % 9999; [userDefaluts setInteger:newPin forKey:self.name]; } - + return newPin; } @@ -119,12 +119,12 @@ dispatch_queue_t backgroundQueue; CFReadStreamRef readStream; CFWriteStreamRef writeStream; CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)ip, portNumber, &readStream, &writeStream); - + if(readStream && writeStream) { CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue); CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue); - + //Setup mInputStream self.inputStream = (__bridge NSInputStream *)readStream; [self.inputStream setDelegate:self]; @@ -132,7 +132,7 @@ dispatch_queue_t backgroundQueue; [self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; }); [self.inputStream open]; - + //Setup outputstream self.outputStream = (__bridge NSOutputStream *)writeStream; [self.outputStream setDelegate:self]; @@ -140,10 +140,10 @@ dispatch_queue_t backgroundQueue; [self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; }); [self.outputStream open]; - + NSArray *temp = [[NSArray alloc]initWithObjects:@"LO_SERVER_CLIENT_PAIR\n", self.name, @"\n", self.pin, @"\n\n", nil]; NSString *command = [temp componentsJoinedByString:@""]; - + [self sendCommand:command]; } } @@ -153,7 +153,7 @@ dispatch_queue_t backgroundQueue; NSLog(@"Sending command %@", aCommand); // UTF-8 as speficied in specification NSData * data = [aCommand dataUsingEncoding:NSUTF8StringEncoding]; - + [self.outputStream write:(uint8_t *)[data bytes] maxLength:[data length]]; } @@ -162,20 +162,21 @@ int count = 0; - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode { switch(eventCode) { case NSStreamEventOpenCompleted:{ - [self stopConnectionTimeoutTimer]; - [[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.connected" object:nil]; - } + [self stopConnectionTimeoutTimer]; + [[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.connected" object:nil]; + } break; case NSStreamEventErrorOccurred:{ [self stopConnectionTimeoutTimer]; + [self disconnect]; NSLog(@"Connection error occured"); [[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.disconnected" object:nil]; - } + } break; case NSStreamEventHasBytesAvailable: { NSMutableData* data; -// NSLog(@"NSStreamEventHasBytesAvailable"); + // NSLog(@"NSStreamEventHasBytesAvailable"); if(!data) { data = [[NSMutableData alloc] init]; } @@ -194,7 +195,7 @@ int count = 0; } } } - + NSArray *commands = [str componentsSeparatedByString:@"\n"]; [self.receiver parse:commands]; data = nil; @@ -202,9 +203,9 @@ int count = 0; } break; default: { - + } - + } } @@ -214,6 +215,8 @@ int count = 0; return; [self.inputStream close]; [self.outputStream close]; + [self.inputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + [self.outputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; self.inputStream = nil; self.outputStream = nil; self.connected = NO; diff --git a/ios/iosremote/iosremote/serverList_vc.m b/ios/iosremote/iosremote/serverList_vc.m index 44853f435e6c..f6f2cf64cbac 100644 --- a/ios/iosremote/iosremote/serverList_vc.m +++ b/ios/iosremote/iosremote/serverList_vc.m @@ -103,7 +103,9 @@ - (void)disableSpinner { - [self.tableView cellForRowAtIndexPath:self.lastSpinningCellIndex].accessoryView = nil; + if ([[self.tableView cellForRowAtIndexPath:self.lastSpinningCellIndex] respondsToSelector:@selector(accessoryView)]) { + [self.tableView cellForRowAtIndexPath:self.lastSpinningCellIndex].accessoryView = nil; + } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath diff --git a/ios/iosremote/iosremote/slideShowSwipeInList.m b/ios/iosremote/iosremote/slideShowSwipeInList.m index 7291b26fc071..55ebdb904fdb 100644 --- a/ios/iosremote/iosremote/slideShowSwipeInList.m +++ b/ios/iosremote/iosremote/slideShowSwipeInList.m @@ -72,7 +72,8 @@ dispatch_queue_t backgroundQueue; - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [self.slideshow size]; + // +1 for stopwatch + return [self.slideshow size]+1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |