@@ -62,45 +62,70 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender
6262// pragma mark - OWSQRScannerDelegate
6363- (void )controller : (OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString : (NSString *)string
6464{
65- NSString *title
66- = NSLocalizedString(@" LINK_DEVICE_PERMISSION_ALERT_TITLE" , @" confirm the users intent to link a new device" );
67- NSString *linkingDescription
68- = NSLocalizedString(@" LINK_DEVICE_PERMISSION_ALERT_BODY" , @" confirm the users intent to link a new device" );
69-
70- UIAlertController *alertController = [UIAlertController alertControllerWithTitle: title
71- message: linkingDescription
72- preferredStyle: UIAlertControllerStyleAlert];
73-
74- UIAlertAction *cancelAction =
65+ OWSDeviceProvisioningURLParser *parser = [[OWSDeviceProvisioningURLParser alloc ] initWithProvisioningURL: string];
66+ if (!parser.isValid ) {
67+ DDLogError (@" Unable to parse provisioning params from QRCode: %@ " , string);
68+
69+ NSString * title = NSLocalizedString(@" LINK_DEVICE_INVALID_CODE_TITLE" , @" report an invalid linking code" );
70+ NSString * body = NSLocalizedString(@" LINK_DEVICE_INVALID_CODE_BODY" , @" report an invalid linking code" );
71+
72+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle: title
73+ message: body
74+ preferredStyle: UIAlertControllerStyleAlert];
75+
76+ UIAlertAction *cancelAction =
7577 [UIAlertAction actionWithTitle: NSLocalizedString(@" TXT_CANCEL_TITLE" , nil )
7678 style: UIAlertActionStyleCancel
7779 handler: ^(UIAlertAction *action) {
7880 dispatch_async (dispatch_get_main_queue (), ^{
7981 [self .navigationController popViewControllerAnimated: YES ];
8082 });
8183 }];
82- [alertController addAction: cancelAction];
83-
84- UIAlertAction *proceedAction =
85- [UIAlertAction actionWithTitle: NSLocalizedString(@" CONFIRM_LINK_NEW_DEVICE_ACTION " , @" Button text " )
84+ [alertController addAction: cancelAction];
85+
86+ UIAlertAction *proceedAction =
87+ [UIAlertAction actionWithTitle: NSLocalizedString(@" LINK_DEVICE_RESTART " , @" attempt another linking " )
8688 style: UIAlertActionStyleDefault
8789 handler: ^(UIAlertAction *action) {
88- [self provisionWithString: string ];
90+ [self .qrScanningController startCapture ];
8991 }];
90- [alertController addAction: proceedAction];
91-
92- [self presentViewController: alertController animated: YES completion: nil ];
92+ [alertController addAction: proceedAction];
93+
94+ [self presentViewController: alertController animated: YES completion: nil ];
95+ } else {
96+ NSString *title
97+ = NSLocalizedString(@" LINK_DEVICE_PERMISSION_ALERT_TITLE" , @" confirm the users intent to link a new device" );
98+ NSString *linkingDescription
99+ = NSLocalizedString(@" LINK_DEVICE_PERMISSION_ALERT_BODY" , @" confirm the users intent to link a new device" );
100+
101+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle: title
102+ message: linkingDescription
103+ preferredStyle: UIAlertControllerStyleAlert];
104+
105+ UIAlertAction *cancelAction =
106+ [UIAlertAction actionWithTitle: NSLocalizedString(@" TXT_CANCEL_TITLE" , nil )
107+ style: UIAlertActionStyleCancel
108+ handler: ^(UIAlertAction *action) {
109+ dispatch_async (dispatch_get_main_queue (), ^{
110+ [self .navigationController popViewControllerAnimated: YES ];
111+ });
112+ }];
113+ [alertController addAction: cancelAction];
114+
115+ UIAlertAction *proceedAction =
116+ [UIAlertAction actionWithTitle: NSLocalizedString(@" CONFIRM_LINK_NEW_DEVICE_ACTION" , @" Button text" )
117+ style: UIAlertActionStyleDefault
118+ handler: ^(UIAlertAction *action) {
119+ [self provisionWithParser: parser];
120+ }];
121+ [alertController addAction: proceedAction];
122+
123+ [self presentViewController: alertController animated: YES completion: nil ];
124+ }
93125}
94126
95- - (void )provisionWithString : ( NSString *)string
127+ - (void )provisionWithParser : (OWSDeviceProvisioningURLParser *)parser
96128{
97- OWSDeviceProvisioningURLParser *parser = [[OWSDeviceProvisioningURLParser alloc ] initWithProvisioningURL: string];
98-
99- if (!parser.isValid ) {
100- DDLogError (@" Unable to parse provisioning params from QRCode: %@ " , string);
101- return ;
102- }
103-
104129 NSData *myPublicKey = [[TSStorageManager sharedManager ] identityKeyPair ].publicKey ;
105130 NSData *myPrivateKey = [[TSStorageManager sharedManager ] identityKeyPair ].ows_privateKey ;
106131 NSString *accountIdentifier = [TSStorageManager localNumber ];
@@ -123,7 +148,7 @@ - (void)provisionWithString:(NSString *)string
123148 dispatch_async (dispatch_get_main_queue (), ^{
124149 [self presentViewController: [self retryAlertControllerWithError: error
125150 retryBlock: ^{
126- [self provisionWithString: string ];
151+ [self provisionWithParser: parser ];
127152 }]
128153 animated: YES
129154 completion: nil ];
0 commit comments