From ea85d7aebd57f49e953e530bcf8723b941b16271 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Fri, 23 Oct 2020 15:12:10 -0700 Subject: [PATCH] Allow pasting in a tsdevice: URL to link a device under TESTABLE_BUILD This is useful for testing in the simulator, which doesn't have camera access. You still have to get the URL out of the QR code, though. --- .../AppSettings/OWSLinkDeviceViewController.h | 2 +- .../AppSettings/OWSLinkDeviceViewController.m | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.h b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.h index 1845ab4440..ef5debb13e 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.h +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.h @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak) id delegate; -- (void)controller:(OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string; +- (void)controller:(nullable OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string; @end diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m index 9ce1901cc2..9672192b04 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m @@ -73,6 +73,13 @@ NS_ASSUME_NONNULL_BEGIN self.title = NSLocalizedString(@"LINK_NEW_DEVICE_TITLE", "Navigation title when scanning QR code to add new device."); + +#if TESTABLE_BUILD + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:LocalizationNotNeeded(@"ENTER") + style:UIBarButtonItemStylePlain + target:self + action:@selector(manuallyEnterLinkURL)]; +#endif } #pragma mark - @@ -100,7 +107,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - OWSQRScannerDelegate -- (void)controller:(OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string +- (void)controller:(nullable OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string { OWSDeviceProvisioningURLParser *parser = [[OWSDeviceProvisioningURLParser alloc] initWithProvisioningURL:string]; if (!parser.isValid) { @@ -242,6 +249,29 @@ NS_ASSUME_NONNULL_BEGIN }]; } +#if TESTABLE_BUILD +- (IBAction)manuallyEnterLinkURL +{ + UIAlertController *alertController = [UIAlertController + alertControllerWithTitle:LocalizationNotNeeded(@"Manually enter linking code.") + message:LocalizationNotNeeded(@"Copy the URL represented by the QR code into the field below.") + preferredStyle:UIAlertControllerStyleAlert]; + [alertController addTextFieldWithConfigurationHandler:nil]; + [alertController + addAction:[UIAlertAction + actionWithTitle:CommonStrings.okayButton + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + [self controller:nil + didDetectQRCodeWithString:[alertController textFields].firstObject.text]; + }]]; + [alertController addAction:[UIAlertAction actionWithTitle:CommonStrings.cancelButton + style:UIAlertActionStyleCancel + handler:nil]]; + [self presentViewController:alertController animated:YES completion:nil]; +} +#endif + #pragma mark - Orientation - (UIInterfaceOrientationMask)supportedInterfaceOrientations