More advanced fixes for push notifications on iOS7

pull/1/head
Frederic Jacobs 11 years ago
parent f771487aab
commit 3031d68523

@ -20,17 +20,8 @@
#import "Util.h" #import "Util.h"
#import "VersionMigrations.h" #import "VersionMigrations.h"
#import <PastelogKit/Pastelog.h> #import <PastelogKit/Pastelog.h>
#define kSignalVersionKey @"SignalUpdateVersionKey" #define kSignalVersionKey @"SignalUpdateVersionKey"
#ifdef __APPLE__ #ifdef __APPLE__

@ -111,6 +111,9 @@
if (SYSTEM_VERSION_LESS_THAN(_iOS_8_0)) { if (SYSTEM_VERSION_LESS_THAN(_iOS_8_0)) {
[UIApplication.sharedApplication registerForRemoteNotificationTypes:(UIRemoteNotificationType)self.mandatoryNotificationTypes]; [UIApplication.sharedApplication registerForRemoteNotificationTypes:(UIRemoteNotificationType)self.mandatoryNotificationTypes];
if ([self isMissingMandatoryNotificationTypes]) {
[self.pushNotificationFutureSource trySetFailure:@"Missing Types"];
}
} else { } else {
[UIApplication.sharedApplication registerForRemoteNotifications]; [UIApplication.sharedApplication registerForRemoteNotifications];
} }
@ -175,8 +178,6 @@
} else{ } else{
return self.wantRemoteNotifications && (!UIApplication.sharedApplication.isRegisteredForRemoteNotifications); return self.wantRemoteNotifications && (!UIApplication.sharedApplication.isRegisteredForRemoteNotifications);
} }
} }
-(BOOL) wantRemoteNotifications { -(BOOL) wantRemoteNotifications {

@ -42,14 +42,14 @@
[self localizeButtonText]; [self localizeButtonText];
DDLogInfo(@"Opened Registration View"); DDLogInfo(@"Opened Registration View");
[self populateDefaultCountryNameAndCode]; [self populateDefaultCountryNameAndCode];
_scrollView.contentSize = _containerView.bounds.size; _scrollView.contentSize = _containerView.bounds.size;
BOOL isRegisteredAlready = Environment.isRegistered; BOOL isRegisteredAlready = Environment.isRegistered;
_registerCancelButton.hidden = !isRegisteredAlready; _registerCancelButton.hidden = !isRegisteredAlready;
[self initializeKeyboardHandlers]; [self initializeKeyboardHandlers];
[self setPlaceholderTextColor:[UIColor lightGrayColor]]; [self setPlaceholderTextColor:[UIColor lightGrayColor]];
} }
@ -58,7 +58,7 @@
RegisterViewController *viewController = [RegisterViewController new]; RegisterViewController *viewController = [RegisterViewController new];
viewController->life = [TOCCancelTokenSource new]; viewController->life = [TOCCancelTokenSource new];
viewController->registered = [TOCFutureSource futureSourceUntil:viewController->life.token]; viewController->registered = [TOCFutureSource futureSourceUntil:viewController->life.token];
return viewController; return viewController;
} }
@ -122,7 +122,7 @@
if(localNumber==nil){ return; } if(localNumber==nil){ return; }
[_phoneNumberTextField resignFirstResponder]; [_phoneNumberTextField resignFirstResponder];
[_registerActivityIndicator startAnimating]; [_registerActivityIndicator startAnimating];
_registerButton.enabled = NO; _registerButton.enabled = NO;
@ -170,28 +170,23 @@
} failure:^(NSURLSessionDataTask *task, NSError *error) { } failure:^(NSURLSessionDataTask *task, NSError *error) {
NSString *alertTitle = NSLocalizedString(@"REGISTRATION_ERROR", @""); NSString *alertTitle = NSLocalizedString(@"REGISTRATION_ERROR", @"");
if ([error isKindOfClass:HttpResponse.class]) { NSHTTPURLResponse* badResponse = (NSHTTPURLResponse*)task.response;
NSHTTPURLResponse* badResponse = (NSHTTPURLResponse*)task.response; if (badResponse.statusCode == 401) {
if (badResponse.statusCode == 401) { SignalAlertView(alertTitle, REGISTER_CHALLENGE_ALERT_VIEW_BODY);
SignalAlertView(alertTitle, REGISTER_CHALLENGE_ALERT_VIEW_BODY); } else if (badResponse.statusCode == 401){
} else if (badResponse.statusCode == 401){ SignalAlertView(alertTitle, NSLocalizedString(@"REGISTER_RATE_LIMITING_BODY", @""));
SignalAlertView(alertTitle, NSLocalizedString(@"REGISTER_RATE_LIMITING_BODY", @"")); } else {
} else { NSString *alertBodyString = [NSString stringWithFormat:@"%@ %lu", NSLocalizedString(@"SERVER_CODE", @""),(unsigned long)badResponse.statusCode];
NSString *alertBodyString = [NSString stringWithFormat:@"%@ %lu", NSLocalizedString(@"SERVER_CODE", @""),(unsigned long)badResponse.statusCode]; SignalAlertView (alertTitle, alertBodyString);
SignalAlertView (alertTitle, alertBodyString);
}
} else{
Environment.errorNoter(error, @"While Verifying Challenge.", NO);
SignalReportError
} }
_challengeButton.enabled = YES; _challengeButton.enabled = YES;
[_challengeActivityIndicator stopAnimating]; [_challengeActivityIndicator stopAnimating];
}]; }];
} }
- (void)showViewNumber:(NSInteger)viewNumber { - (void)showViewNumber:(NSInteger)viewNumber {
if (viewNumber == REGISTER_VIEW_NUMBER) { if (viewNumber == REGISTER_VIEW_NUMBER) {
[_registerActivityIndicator stopAnimating]; [_registerActivityIndicator stopAnimating];
_registerButton.enabled = YES; _registerButton.enabled = YES;
@ -219,7 +214,7 @@
NSDate *now = [NSDate new]; NSDate *now = [NSDate new];
timeoutDate = [[NSDate alloc] initWithTimeInterval:smsTimeoutTimeInterval sinceDate:now]; timeoutDate = [[NSDate alloc] initWithTimeInterval:smsTimeoutTimeInterval sinceDate:now];
countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1 countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1
target:self target:self
selector:@selector(countdowntimerFired) selector:@selector(countdowntimerFired)
@ -237,9 +232,9 @@
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:now toDate:timeoutDate options:0]; NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:now toDate:timeoutDate options:0];
NSString* timeLeft = [NSString stringWithFormat:@"%ld:%02ld",(long)[conversionInfo minute],(long)[conversionInfo second]]; NSString* timeLeft = [NSString stringWithFormat:@"%ld:%02ld",(long)[conversionInfo minute],(long)[conversionInfo second]];
[self.voiceChallengeTextLabel setText:timeLeft]; [self.voiceChallengeTextLabel setText:timeLeft];
if (0 <= [now compare:timeoutDate]) { if (0 <= [now compare:timeoutDate]) {
[self initiateVoiceVerification]; [self initiateVoiceVerification];
} }
@ -271,7 +266,7 @@
- (void)initializeKeyboardHandlers{ - (void)initializeKeyboardHandlers{
UITapGestureRecognizer *outsideTabRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboardFromAppropriateSubView)]; UITapGestureRecognizer *outsideTabRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboardFromAppropriateSubView)];
[self.view addGestureRecognizer:outsideTabRecognizer]; [self.view addGestureRecognizer:outsideTabRecognizer];
[self observeKeyboardNotifications]; [self observeKeyboardNotifications];
} }
@ -285,7 +280,7 @@
selector:@selector(keyboardWillShow:) selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification name:UIKeyboardWillShowNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:) selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification name:UIKeyboardWillHideNotification
@ -341,7 +336,7 @@
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString* textBeforeChange = textField.text; NSString* textBeforeChange = textField.text;
// backspacing should skip over formatting characters // backspacing should skip over formatting characters
UITextPosition *posIfBackspace = [textField positionFromPosition:textField.beginningOfDocument UITextPosition *posIfBackspace = [textField positionFromPosition:textField.beginningOfDocument
offset:(NSInteger)(range.location + range.length)]; offset:(NSInteger)(range.location + range.length)];
@ -362,7 +357,7 @@
// make the proposed change // make the proposed change
NSString* textAfterChange = [textBeforeChange withCharactersInRange:range replacedBy:string]; NSString* textAfterChange = [textBeforeChange withCharactersInRange:range replacedBy:string];
NSUInteger cursorPositionAfterChange = range.location + string.length; NSUInteger cursorPositionAfterChange = range.location + string.length;
// reformat the phone number, trying to keep the cursor beside the inserted or deleted digit // reformat the phone number, trying to keep the cursor beside the inserted or deleted digit
bool isJustDeletion = string.length == 0; bool isJustDeletion = string.length == 0;
NSString* textAfterReformat = [PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:textAfterChange.digitsOnly NSString* textAfterReformat = [PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:textAfterChange.digitsOnly
@ -375,7 +370,7 @@
UITextPosition *pos = [textField positionFromPosition:textField.beginningOfDocument UITextPosition *pos = [textField positionFromPosition:textField.beginningOfDocument
offset:(NSInteger)cursorPositionAfterReformat]; offset:(NSInteger)cursorPositionAfterReformat];
[textField setSelectedTextRange:[textField textRangeFromPosition:pos toPosition:pos]]; [textField setSelectedTextRange:[textField textRangeFromPosition:pos toPosition:pos]];
return NO; // inform our caller that we took care of performing the change return NO; // inform our caller that we took care of performing the change
} }

Loading…
Cancel
Save