mirror of https://github.com/oxen-io/session-ios
				
				
				
			Show re-registration in app settings.
							parent
							
								
									7f346326f6
								
							
						
					
					
						commit
						010c10cb0c
					
				@ -0,0 +1,15 @@
 | 
			
		||||
//
 | 
			
		||||
//  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_BEGIN
 | 
			
		||||
 | 
			
		||||
@interface RegistrationUtils : NSObject
 | 
			
		||||
 | 
			
		||||
- (instancetype)init NS_UNAVAILABLE;
 | 
			
		||||
 | 
			
		||||
+ (void)showReregistrationUIFromViewController:(UIViewController *)fromViewController;
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_END
 | 
			
		||||
@ -0,0 +1,91 @@
 | 
			
		||||
//
 | 
			
		||||
//  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#import "RegistrationUtils.h"
 | 
			
		||||
#import "CodeVerificationViewController.h"
 | 
			
		||||
#import "OWSNavigationController.h"
 | 
			
		||||
#import <SignalMessaging/Environment.h>
 | 
			
		||||
#import <SignalMessaging/SignalMessaging-Swift.h>
 | 
			
		||||
#import <SignalServiceKit/TSAccountManager.h>
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_BEGIN
 | 
			
		||||
 | 
			
		||||
@implementation RegistrationUtils
 | 
			
		||||
 | 
			
		||||
+ (void)showReregistrationUIFromViewController:(UIViewController *)fromViewController
 | 
			
		||||
{
 | 
			
		||||
    UIAlertController *actionSheetController =
 | 
			
		||||
        [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
 | 
			
		||||
 | 
			
		||||
    [actionSheetController
 | 
			
		||||
        addAction:[UIAlertAction
 | 
			
		||||
                      actionWithTitle:NSLocalizedString(@"DEREGISTRATION_REREGISTER_WITH_SAME_PHONE_NUMBER",
 | 
			
		||||
                                          @"Label for button that lets users re-register using the same phone number.")
 | 
			
		||||
                                style:UIAlertActionStyleDestructive
 | 
			
		||||
                              handler:^(UIAlertAction *action) {
 | 
			
		||||
                                  [RegistrationUtils reregisterWithFromViewController:fromViewController];
 | 
			
		||||
                              }]];
 | 
			
		||||
 | 
			
		||||
    [actionSheetController addAction:[OWSAlerts cancelAction]];
 | 
			
		||||
 | 
			
		||||
    [fromViewController presentViewController:actionSheetController animated:YES completion:nil];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
+ (void)reregisterWithFromViewController:(UIViewController *)fromViewController
 | 
			
		||||
{
 | 
			
		||||
    DDLogInfo(@"%@ reregisterWithSamePhoneNumber.", self.logTag);
 | 
			
		||||
 | 
			
		||||
    if (![[TSAccountManager sharedInstance] resetForReregistration]) {
 | 
			
		||||
        OWSFail(@"%@ could not reset for re-registration.", self.logTag);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [[Environment current].preferences unsetRecordedAPNSTokens];
 | 
			
		||||
 | 
			
		||||
    [ModalActivityIndicatorViewController
 | 
			
		||||
        presentFromViewController:fromViewController
 | 
			
		||||
                        canCancel:NO
 | 
			
		||||
                  backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
 | 
			
		||||
                      [TSAccountManager
 | 
			
		||||
                          registerWithPhoneNumber:[TSAccountManager sharedInstance].reregisterationPhoneNumber
 | 
			
		||||
                          success:^{
 | 
			
		||||
                              DDLogInfo(@"%@ re-registering: send verification code succeeded.", self.logTag);
 | 
			
		||||
 | 
			
		||||
                              dispatch_async(dispatch_get_main_queue(), ^{
 | 
			
		||||
                                  [modalActivityIndicator dismissWithCompletion:^{
 | 
			
		||||
                                      CodeVerificationViewController *viewController =
 | 
			
		||||
                                          [CodeVerificationViewController new];
 | 
			
		||||
 | 
			
		||||
                                      OWSNavigationController *navigationController =
 | 
			
		||||
                                          [[OWSNavigationController alloc] initWithRootViewController:viewController];
 | 
			
		||||
                                      navigationController.navigationBarHidden = YES;
 | 
			
		||||
 | 
			
		||||
                                      [UIApplication sharedApplication].delegate.window.rootViewController
 | 
			
		||||
                                          = navigationController;
 | 
			
		||||
                                  }];
 | 
			
		||||
                              });
 | 
			
		||||
                          }
 | 
			
		||||
                          failure:^(NSError *error) {
 | 
			
		||||
                              DDLogError(@"%@ re-registering: send verification code failed.", self.logTag);
 | 
			
		||||
 | 
			
		||||
                              dispatch_async(dispatch_get_main_queue(), ^{
 | 
			
		||||
                                  [modalActivityIndicator dismissWithCompletion:^{
 | 
			
		||||
                                      if (error.code == 400) {
 | 
			
		||||
                                          [OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTRATION_ERROR", nil)
 | 
			
		||||
                                                                message:NSLocalizedString(
 | 
			
		||||
                                                                            @"REGISTRATION_NON_VALID_NUMBER", nil)];
 | 
			
		||||
                                      } else {
 | 
			
		||||
                                          [OWSAlerts showAlertWithTitle:error.localizedDescription
 | 
			
		||||
                                                                message:error.localizedRecoverySuggestion];
 | 
			
		||||
                                      }
 | 
			
		||||
                                  }];
 | 
			
		||||
                              });
 | 
			
		||||
                          }
 | 
			
		||||
                          smsVerification:YES];
 | 
			
		||||
                  }];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
NS_ASSUME_NONNULL_END
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue