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); 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..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 - @@ -91,7 +92,7 @@ - (void)processPin { if (!self.enteredPin) { - [self startPinConfirmation]; + [self validatePin]; } else { @@ -99,6 +100,12 @@ - (void)processPin } } +- (void)invalidateCurrentPin +{ + self.enteredPin = nil; + self.currentPin = @""; +} + - (void)startPinConfirmation { self.enteredPin = self.currentPin; @@ -106,7 +113,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 +142,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/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) { 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 {