From a1503a380076d05c2ed3c4d3f7aaaa3a8052e608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=CC=81mi=20Dayres?= Date: Thu, 4 Feb 2016 17:33:49 +0100 Subject: [PATCH 1/4] add pin validation feature --- .../ABPadLockScreenSetupViewController.h | 3 ++ .../ABPadLockScreenSetupViewController.m | 53 ++++++++++++++----- .../Your Modules/ExampleViewController.m | 5 ++ .../ViewController.swift | 5 ++ 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/ABPadLockScreen/ABPadLockScreenSetupViewController.h b/ABPadLockScreen/ABPadLockScreenSetupViewController.h index 409375b..375a129 100755 --- a/ABPadLockScreen/ABPadLockScreenSetupViewController.h +++ b/ABPadLockScreen/ABPadLockScreenSetupViewController.h @@ -37,6 +37,7 @@ @property (nonatomic, strong, readonly) NSString *subtitleLabelText; @property (nonatomic, strong) NSString *pinNotMatchedText; @property (nonatomic, strong) NSString *pinConfirmationText; +@property (nonatomic, strong) NSString *invalidPinText; - (instancetype)initWithDelegate:(id)delegate; - (instancetype)initWithDelegate:(id)delegate complexPin:(BOOL)complexPin; @@ -48,5 +49,7 @@ @required - (void)pinSet:(NSString *)pin padLockScreenSetupViewController:(ABPadLockScreenSetupViewController *)padLockScreenViewController; - (void)unlockWasCancelledForSetupViewController:(ABPadLockScreenAbstractViewController *)padLockScreenViewController; +@optional +- (BOOL)isValidPin:(NSString *)pin padLockScreenSetupViewController:(ABPadLockScreenSetupViewController *)padLockScreenViewController; @end \ No newline at end of file diff --git a/ABPadLockScreen/ABPadLockScreenSetupViewController.m b/ABPadLockScreen/ABPadLockScreenSetupViewController.m index 24221c7..8767878 100755 --- a/ABPadLockScreen/ABPadLockScreenSetupViewController.m +++ b/ABPadLockScreen/ABPadLockScreenSetupViewController.m @@ -91,7 +91,7 @@ - (void)processPin { if (!self.enteredPin) { - [self startPinConfirmation]; + [self validatePin]; } else { @@ -99,6 +99,12 @@ - (void)processPin } } +- (void)invalidateCurrentPin +{ + self.enteredPin = nil; + self.currentPin = @""; +} + - (void)startPinConfirmation { self.enteredPin = self.currentPin; @@ -106,7 +112,24 @@ - (void)startPinConfirmation [lockScreenView updateDetailLabelWithString:self.pinConfirmationText animated:YES completion:nil]; [lockScreenView resetAnimated:YES]; } - + +- (void)validatePin +{ + BOOL isValidPin = YES; + if ([self.setupScreenDelegate respondsToSelector:@selector(isValidPin:padLockScreenSetupViewController:)]) + { + isValidPin = [self.setupScreenDelegate isValidPin:self.currentPin padLockScreenSetupViewController:self]; + } + if (isValidPin) + { + [self startPinConfirmation]; + } + else + { + [self resetPinWithErrorString:self.invalidPinText]; + } +} + - (void)validateConfirmedPin { if ([self.currentPin isEqualToString:self.enteredPin]) @@ -118,17 +141,21 @@ - (void)validateConfirmedPin } else { - [lockScreenView updateDetailLabelWithString:self.pinNotMatchedText animated:YES completion:nil]; - [lockScreenView animateFailureNotification]; - [lockScreenView resetAnimated:YES]; - self.enteredPin = nil; - self.currentPin = @""; - - // viberate feedback - if (self.errorVibrateEnabled) - { - AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); - } + [self resetPinWithErrorString:self.pinNotMatchedText]; + } +} + +- (void)resetPinWithErrorString:(NSString *)errorString { + [lockScreenView updateDetailLabelWithString:errorString animated:YES completion:nil]; + [lockScreenView animateFailureNotification]; + [lockScreenView resetAnimated:YES]; + self.enteredPin = nil; + self.currentPin = @""; + + // viberate feedback + if (self.errorVibrateEnabled) + { + AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); } } diff --git a/ABPadLockScreenDemo/ABPadLockScreenDemo/Your Modules/ExampleViewController.m b/ABPadLockScreenDemo/ABPadLockScreenDemo/Your Modules/ExampleViewController.m index 0c5a3fa..1ca7952 100644 --- a/ABPadLockScreenDemo/ABPadLockScreenDemo/Your Modules/ExampleViewController.m +++ b/ABPadLockScreenDemo/ABPadLockScreenDemo/Your Modules/ExampleViewController.m @@ -48,6 +48,7 @@ - (IBAction)setPin:(id)sender ABPadLockScreenSetupViewController *lockScreen = [[ABPadLockScreenSetupViewController alloc] initWithDelegate:self complexPin:YES subtitleLabelText:@"You need a PIN to continue"]; lockScreen.tapSoundEnabled = YES; lockScreen.errorVibrateEnabled = YES; + lockScreen.invalidPinText = @"Invalid pin"; lockScreen.modalPresentationStyle = UIModalPresentationFullScreen; lockScreen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; @@ -126,4 +127,8 @@ - (void)unlockWasCancelledForSetupViewController:(ABPadLockScreenAbstractViewCon NSLog(@"Pin Setup Cnaclled"); } +- (BOOL)isValidPin:(NSString *)pin padLockScreenSetupViewController:(ABPadLockScreenSetupViewController *)padLockScreenViewController { + return ![pin isEqualToString:@"0000"]; +} + @end diff --git a/ABPadLockScreenSwiftDemo/ABPadLockScreenSwiftDemo/ViewController.swift b/ABPadLockScreenSwiftDemo/ABPadLockScreenSwiftDemo/ViewController.swift index 0e278b9..591cd12 100644 --- a/ABPadLockScreenSwiftDemo/ABPadLockScreenSwiftDemo/ViewController.swift +++ b/ABPadLockScreenSwiftDemo/ABPadLockScreenSwiftDemo/ViewController.swift @@ -50,6 +50,7 @@ class ViewController: UIViewController, ABPadLockScreenSetupViewControllerDelega @IBAction func setPinSelected(sender: AnyObject) { let lockSetupScreen = ABPadLockScreenSetupViewController(delegate: self, complexPin: false, subtitleLabelText: "Select a pin") + lockSetupScreen.invalidPinText = "Invalid pin" lockSetupScreen.tapSoundEnabled = true lockSetupScreen.errorVibrateEnabled = true lockSetupScreen.modalPresentationStyle = UIModalPresentationStyle.FullScreen @@ -67,6 +68,10 @@ class ViewController: UIViewController, ABPadLockScreenSetupViewControllerDelega func unlockWasCancelledForSetupViewController(padLockScreenViewController: ABPadLockScreenAbstractViewController!) { dismissViewControllerAnimated(true, completion: nil) } + + func isValidPin(pin: String!, padLockScreenSetupViewController padLockScreenViewController: ABPadLockScreenSetupViewController!) -> Bool { + return pin != "0000" + } //MARK: Lock Screen Delegate func padLockScreenViewController(padLockScreenViewController: ABPadLockScreenViewController!, validatePin pin: String!) -> Bool { From 99fc000e10bbaecbb0c17794e2d2b3ebfedf3202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=CC=81mi=20Dayres?= Date: Thu, 4 Feb 2016 17:51:26 +0100 Subject: [PATCH 2/4] add default text for invalidPinText --- ABPadLockScreen/ABPadLockScreenSetupViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ABPadLockScreen/ABPadLockScreenSetupViewController.m b/ABPadLockScreen/ABPadLockScreenSetupViewController.m index 8767878..92a775a 100755 --- a/ABPadLockScreen/ABPadLockScreenSetupViewController.m +++ b/ABPadLockScreen/ABPadLockScreenSetupViewController.m @@ -75,6 +75,7 @@ - (void)setDefaultTexts { _pinNotMatchedText = NSLocalizedString(@"Pincode did not match.", @""); _pinConfirmationText = NSLocalizedString(@"Re-enter your new pincode", @""); + _invalidPinText = NSLocalizedString(@"Invalid pincode", @""); } #pragma mark - From c6348c0f3aba306bbe6b5af7f5c60145a0ba553b Mon Sep 17 00:00:00 2001 From: Mickael Laloum Date: Thu, 14 Apr 2016 15:23:45 +0200 Subject: [PATCH 3/4] do not update the AttemptLeft Label --- ABPadLockScreen/ABPadLockScreenViewController.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ABPadLockScreen/ABPadLockScreenViewController.m b/ABPadLockScreen/ABPadLockScreenViewController.m index a9b7418..6cabbb6 100755 --- a/ABPadLockScreen/ABPadLockScreenViewController.m +++ b/ABPadLockScreen/ABPadLockScreenViewController.m @@ -123,13 +123,17 @@ - (void)processFailure if (self.remainingAttempts > 1) { - [lockScreenView updateDetailLabelWithString:[NSString stringWithFormat:@"%ld %@", (long)self.remainingAttempts, self.pluralAttemptsLeftString] - animated:YES completion:nil]; + if (self.pluralAttemptsLeftString) { + [lockScreenView updateDetailLabelWithString:[NSString stringWithFormat:@"%ld %@", (long)self.remainingAttempts, self.pluralAttemptsLeftString] + animated:YES completion:nil]; + } } else if (self.remainingAttempts == 1) { - [lockScreenView updateDetailLabelWithString:[NSString stringWithFormat:@"%ld %@", (long)self.remainingAttempts, self.singleAttemptLeftString] - animated:YES completion:nil]; + if (self.singleAttemptLeftString) { + [lockScreenView updateDetailLabelWithString:[NSString stringWithFormat:@"%ld %@", (long)self.remainingAttempts, self.singleAttemptLeftString] + animated:YES completion:nil]; + } } else if (self.remainingAttempts == 0) { From a1799701bfd40e354944778403fa0b2e89558677 Mon Sep 17 00:00:00 2001 From: Mickael Laloum Date: Thu, 14 Apr 2016 17:08:56 +0200 Subject: [PATCH 4/4] fix background --- ABPadLockScreen/ABPadLockScreenAbstractViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ABPadLockScreen/ABPadLockScreenAbstractViewController.m b/ABPadLockScreen/ABPadLockScreenAbstractViewController.m index 664e407..d720870 100755 --- a/ABPadLockScreen/ABPadLockScreenAbstractViewController.m +++ b/ABPadLockScreen/ABPadLockScreenAbstractViewController.m @@ -108,7 +108,7 @@ - (UIStatusBarStyle)preferredStatusBarStyle if(color == nil) { - color = lockScreenView.backgroundColor = [UIColor blackColor]; + color = [UIColor blackColor]; } const CGFloat *componentColors = CGColorGetComponents(color.CGColor);