Fix some pairing glitches and add a cancel button

This commit is contained in:
Cameron Gutman
2016-10-21 12:07:29 -07:00
parent fd50b71b16
commit ce95f2c153
2 changed files with 20 additions and 12 deletions
+4 -1
View File
@@ -68,12 +68,15 @@
} }
NSInteger pairedStatus; NSInteger pairedStatus;
if (![pairResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) { if (![pairResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) {
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
[_callback pairFailed:@"Pairing was declined by the target."]; [_callback pairFailed:@"Pairing was declined by the target."];
return; return;
} }
NSString* plainCert = [pairResp getStringTag:@"plaincert"]; NSString* plainCert = [pairResp getStringTag:@"plaincert"];
if ([plainCert length] == 0) {
[_callback pairFailed:@"Another pairing attempt is already in progress."];
return;
}
CryptoManager* cryptoMan = [[CryptoManager alloc] init]; CryptoManager* cryptoMan = [[CryptoManager alloc] init];
NSData* aesKey; NSData* aesKey;
@@ -48,21 +48,26 @@ static NSMutableSet* hostList;
_pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing" _pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing"
message:[NSString stringWithFormat:@"Enter the following PIN on the host machine: %@", PIN] message:[NSString stringWithFormat:@"Enter the following PIN on the host machine: %@", PIN]
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
[_pairAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action) {
[_discMan startDiscovery];
[self hideLoadingFrame];
}]];
[self presentViewController:_pairAlert animated:YES completion:nil]; [self presentViewController:_pairAlert animated:YES completion:nil];
}); });
} }
- (void)pairFailed:(NSString *)message { - (void)pairFailed:(NSString *)message {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_pairAlert dismissViewControllerAnimated:YES completion:nil]; [_pairAlert dismissViewControllerAnimated:YES completion:^{
_pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing Failed" _pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing Failed"
message:message message:message
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
[_pairAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]]; [_pairAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]];
[self presentViewController:_pairAlert animated:YES completion:nil]; [self presentViewController:_pairAlert animated:YES completion:nil];
[_discMan startDiscovery]; [_discMan startDiscovery];
[self hideLoadingFrame]; [self hideLoadingFrame];
}];
}); });
} }
@@ -581,8 +586,8 @@ static NSMutableSet* hostList;
-(void)handleReturnToForeground -(void)handleReturnToForeground
{ {
// This will refresh the applist // This will refresh the applist when a paired host is selected
if (_selectedHost != nil) { if (_selectedHost != nil && _selectedHost.pairState == PairStatePaired) {
[self hostClicked:_selectedHost view:nil]; [self hostClicked:_selectedHost view:nil];
} }
} }