|
|
|
@ -12,9 +12,20 @@
|
|
|
|
|
#import "TSAccountManager.h"
|
|
|
|
|
#import "UIView+OWS.h"
|
|
|
|
|
#import "ViewControllerUtils.h"
|
|
|
|
|
#import <SAMKeychain/SAMKeychain.h>
|
|
|
|
|
|
|
|
|
|
@interface RegistrationViewController () <CountryCodeViewControllerDelegate>
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
|
|
NSString *const kNSUserDefaultsKey_LastRegisteredCountryCode = @"kNSUserDefaultsKey_LastRegisteredCountryCode";
|
|
|
|
|
NSString *const kNSUserDefaultsKey_LastRegisteredPhoneNumber = @"kNSUserDefaultsKey_LastRegisteredPhoneNumber";
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
@interface RegistrationViewController () <CountryCodeViewControllerDelegate, UITextFieldDelegate>
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) NSString *countryCode;
|
|
|
|
|
@property (nonatomic) NSString *callingCode;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) UILabel *countryCodeLabel;
|
|
|
|
@ -194,7 +205,7 @@
|
|
|
|
|
ofView:separatorView2
|
|
|
|
|
withOffset:ScaleFromIPhone5To7Plus(12.f, 15.f)];
|
|
|
|
|
[activateButton autoSetDimension:ALDimensionHeight toSize:47.f];
|
|
|
|
|
[activateButton addTarget:self action:@selector(sendCodeAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
[activateButton addTarget:self action:@selector(sendCodeAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
|
|
|
|
UIActivityIndicatorView *spinnerView =
|
|
|
|
|
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
|
|
|
|
@ -237,6 +248,14 @@
|
|
|
|
|
- (void)populateDefaultCountryNameAndCode {
|
|
|
|
|
NSLocale *locale = NSLocale.currentLocale;
|
|
|
|
|
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if ([self lastRegisteredCountryCode].length > 0) {
|
|
|
|
|
countryCode = [self lastRegisteredCountryCode];
|
|
|
|
|
}
|
|
|
|
|
self.phoneNumberTextField.text = [self lastRegisteredPhoneNumber];
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
NSNumber *callingCode = [[PhoneNumberUtil sharedUtil].nbPhoneNumberUtil getCountryCodeForRegion:countryCode];
|
|
|
|
|
NSString *countryName = [PhoneNumberUtil countryNameFromCountryCode:countryCode];
|
|
|
|
|
[self updateCountryWithName:countryName
|
|
|
|
@ -249,7 +268,12 @@
|
|
|
|
|
- (void)updateCountryWithName:(NSString *)countryName
|
|
|
|
|
callingCode:(NSString *)callingCode
|
|
|
|
|
countryCode:(NSString *)countryCode {
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
OWSAssert(countryName.length > 0);
|
|
|
|
|
OWSAssert(callingCode.length > 0);
|
|
|
|
|
OWSAssert(countryCode.length > 0);
|
|
|
|
|
|
|
|
|
|
_countryCode = countryCode;
|
|
|
|
|
_callingCode = callingCode;
|
|
|
|
|
|
|
|
|
|
NSString *title = [NSString stringWithFormat:@"%@ (%@)",
|
|
|
|
@ -277,7 +301,7 @@
|
|
|
|
|
message:NSLocalizedString(@"EXISTING_USER_REGISTRATION_ALERT_BODY", @"during registration")];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)sendCodeAction:(id)sender
|
|
|
|
|
- (void)sendCodeAction
|
|
|
|
|
{
|
|
|
|
|
NSString *phoneNumberText =
|
|
|
|
|
[_phoneNumberTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
@ -290,6 +314,7 @@
|
|
|
|
|
@"Message of alert indicating that users needs to enter a phone number to register.")];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
NSString *countryCode = self.countryCode;
|
|
|
|
|
NSString *phoneNumber = [NSString stringWithFormat:@"%@%@", _callingCode, phoneNumberText];
|
|
|
|
|
PhoneNumber *localNumber = [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:phoneNumber];
|
|
|
|
|
NSString *parsedPhoneNumber = localNumber.toE164;
|
|
|
|
@ -314,6 +339,11 @@
|
|
|
|
|
|
|
|
|
|
CodeVerificationViewController *vc = [CodeVerificationViewController new];
|
|
|
|
|
[weakSelf.navigationController pushViewController:vc animated:YES];
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
[weakSelf setLastRegisteredCountryCode:countryCode];
|
|
|
|
|
[weakSelf setLastRegisteredPhoneNumber:phoneNumberText];
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
failure:^(NSError *error) {
|
|
|
|
|
if (error.code == 400) {
|
|
|
|
@ -396,9 +426,54 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
|
|
|
|
|
[self sendCodeAction:nil];
|
|
|
|
|
[self sendCodeAction];
|
|
|
|
|
[textField resignFirstResponder];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Debug
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
|
|
- (NSString *_Nullable)debugValueForKey:(NSString *)key
|
|
|
|
|
{
|
|
|
|
|
OWSCAssert([NSThread isMainThread]);
|
|
|
|
|
OWSCAssert(key.length > 0);
|
|
|
|
|
|
|
|
|
|
return [[NSUserDefaults standardUserDefaults] stringForKey:key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setDebugValue:(NSString *)value forKey:(NSString *)key
|
|
|
|
|
{
|
|
|
|
|
OWSCAssert([NSThread isMainThread]);
|
|
|
|
|
OWSCAssert(key.length > 0);
|
|
|
|
|
OWSCAssert(value.length > 0);
|
|
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setValue:value forKey:key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *_Nullable)lastRegisteredCountryCode
|
|
|
|
|
{
|
|
|
|
|
return [self debugValueForKey:kNSUserDefaultsKey_LastRegisteredCountryCode];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setLastRegisteredCountryCode:(NSString *)value
|
|
|
|
|
{
|
|
|
|
|
[self setDebugValue:value forKey:kNSUserDefaultsKey_LastRegisteredCountryCode];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *_Nullable)lastRegisteredPhoneNumber
|
|
|
|
|
{
|
|
|
|
|
return [self debugValueForKey:kNSUserDefaultsKey_LastRegisteredPhoneNumber];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setLastRegisteredPhoneNumber:(NSString *)value
|
|
|
|
|
{
|
|
|
|
|
[self setDebugValue:value forKey:kNSUserDefaultsKey_LastRegisteredPhoneNumber];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|
|