restart searching whenever connection failed

Change-Id: I56bacb9953a07054da08546b982a1379de8e6642
This commit is contained in:
Siqi LIU 2013-08-14 00:05:16 +08:00
parent 03b7dde22c
commit 8f44dc9a04
4 changed files with 21 additions and 9 deletions

View File

@ -8,11 +8,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "iosremote/Communication/CommunicationManager.m" filePath = "iosremote/Communication/CommunicationManager.m"
timestampString = "397932312.890248" timestampString = "398102600.954242"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "77" startingLineNumber = "78"
endingLineNumber = "77" endingLineNumber = "78"
landmarkName = "-connectionStatusHandler:" landmarkName = "-connectionStatusHandler:"
landmarkType = "5"> landmarkType = "5">
</FileBreakpoint> </FileBreakpoint>

View File

@ -71,6 +71,7 @@
otherButtonTitles:NSLocalizedString(@"Help", nil), nil]; otherButtonTitles:NSLocalizedString(@"Help", nil), nil];
[message show]; [message show];
}); });
[(server_list_vc *)self.delegate startSearching];
} else { } else {
[[self.delegate navigationController] popToRootViewControllerAnimated:YES]; [[self.delegate navigationController] popToRootViewControllerAnimated:YES];
BasePresentationViewController *bpvc = [[(MainSplitViewController *)[self.delegate presentingViewController] viewControllers] objectAtIndex:1]; BasePresentationViewController *bpvc = [[(MainSplitViewController *)[self.delegate presentingViewController] viewControllers] objectAtIndex:1];

View File

@ -14,4 +14,5 @@
@property (strong, nonatomic) IBOutlet UITableView *serverTable; @property (strong, nonatomic) IBOutlet UITableView *serverTable;
- (void) startSearching;
@end @end

View File

@ -24,8 +24,8 @@
@property (nonatomic, strong) id slideShowPreviewStartObserver; @property (nonatomic, strong) id slideShowPreviewStartObserver;
@property (nonatomic, strong) id pinValidationObserver; @property (nonatomic, strong) id pinValidationObserver;
@property (atomic, strong) NSIndexPath *lastSpinningCellIndex; @property (atomic, strong) NSIndexPath *lastSpinningCellIndex;
@property (nonatomic, strong) NSNetServiceBrowser *serviceBrowser; @property (nonatomic, strong) NSNetServiceBrowser *serviceBrowser;
@property (nonatomic, strong) NSTimer *searchLabelTimer; @property (nonatomic, strong) NSTimer *searchLabelTimer;
@property (nonatomic, strong) NSTimer *searchTimeoutTimer; @property (nonatomic, strong) NSTimer *searchTimeoutTimer;
@property (nonatomic, strong) NSString *searchStateText; @property (nonatomic, strong) NSString *searchStateText;
@ -46,6 +46,13 @@
@synthesize serviceBrowser = _serviceBrowser; @synthesize serviceBrowser = _serviceBrowser;
#pragma mark - helper #pragma mark - helper
- (void) startSearching
{
[self.comManager.autoDiscoveryServers removeAllObjects];
[self.serviceBrowser searchForServicesOfType:@"_impressremote._tcp" inDomain:@"local"];
[self.serviceBrowser scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
- (void) setSearchStateText:(NSString *)searchStateText - (void) setSearchStateText:(NSString *)searchStateText
{ {
_searchStateText = searchStateText; _searchStateText = searchStateText;
@ -75,6 +82,9 @@
-(void) netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict -(void) netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict
{ {
NSLog(@"Failed to resolve"); NSLog(@"Failed to resolve");
[self.comManager.autoDiscoveryServers removeAllObjects];
[self startSearching];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Failed to reach your computer", nil) UIAlertView *message = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Failed to reach your computer", nil)
message:NSLocalizedString(@"Please consider restart LibreOffice Impress on your computer.", nil) message:NSLocalizedString(@"Please consider restart LibreOffice Impress on your computer.", nil)
delegate:self delegate:self
@ -140,7 +150,6 @@
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict
{ {
NSLog(@"search error"); NSLog(@"search error");
// [self.serviceBrowser searchForServicesOfType:@"_impressRemote._tcp" inDomain:@"local"];
} }
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser
@ -158,6 +167,9 @@
if(!moreComing) if(!moreComing)
{ {
[self.tableView reloadData]; [self.tableView reloadData];
[self.serviceBrowser stop];
[self.searchTimeoutTimer invalidate];
[self.searchLabelTimer invalidate];
} }
} }
@ -245,8 +257,7 @@
[self.serverTable reloadData]; [self.serverTable reloadData];
self.serviceBrowser = [[NSNetServiceBrowser alloc] init]; self.serviceBrowser = [[NSNetServiceBrowser alloc] init];
[self.serviceBrowser setDelegate:self]; [self.serviceBrowser setDelegate:self];
[self.serviceBrowser searchForServicesOfType:@"_impressremote._tcp" inDomain:@"local"]; [self startSearching];
[self.serviceBrowser scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[super viewDidAppear:animated]; [super viewDidAppear:animated];
} }
@ -299,8 +310,7 @@
if ([self.comManager.autoDiscoveryServers count] == 0 && indexPath.section == 0){ if ([self.comManager.autoDiscoveryServers count] == 0 && indexPath.section == 0){
// No discovered server and not searching => in a "click to refresh" state, so we restart searching process // No discovered server and not searching => in a "click to refresh" state, so we restart searching process
if (self.comManager.searchState == WAITING){ if (self.comManager.searchState == WAITING){
[self.serviceBrowser searchForServicesOfType:@"_impressremote._tcp" inDomain:@"local"]; [self startSearching];
[self.serviceBrowser scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
} }
// Return when browser is still searching... // Return when browser is still searching...
return; return;