Skip to content
This repository was archived by the owner on Apr 11, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ABPadLockScreen/ABPadLockScreenAbstractViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ - (UIStatusBarStyle)preferredStatusBarStyle

if(color == nil)
{
color = lockScreenView.backgroundColor = [UIColor blackColor];
color = [UIColor blackColor];
}

const CGFloat *componentColors = CGColorGetComponents(color.CGColor);
Expand Down
3 changes: 3 additions & 0 deletions ABPadLockScreen/ABPadLockScreenSetupViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ABPadLockScreenSetupViewControllerDelegate>)delegate;
- (instancetype)initWithDelegate:(id<ABPadLockScreenSetupViewControllerDelegate>)delegate complexPin:(BOOL)complexPin;
Expand All @@ -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
54 changes: 41 additions & 13 deletions ABPadLockScreen/ABPadLockScreenSetupViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand All @@ -91,22 +92,45 @@ - (void)processPin
{
if (!self.enteredPin)
{
[self startPinConfirmation];
[self validatePin];
}
else
{
[self validateConfirmedPin];
}
}

- (void)invalidateCurrentPin
{
self.enteredPin = nil;
self.currentPin = @"";
}

- (void)startPinConfirmation
{
self.enteredPin = self.currentPin;
self.currentPin = @"";
[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])
Expand All @@ -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);
}
}

Expand Down
12 changes: 8 additions & 4 deletions ABPadLockScreen/ABPadLockScreenViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,4 +127,8 @@ - (void)unlockWasCancelledForSetupViewController:(ABPadLockScreenAbstractViewCon
NSLog(@"Pin Setup Cnaclled");
}

- (BOOL)isValidPin:(NSString *)pin padLockScreenSetupViewController:(ABPadLockScreenSetupViewController *)padLockScreenViewController {
return ![pin isEqualToString:@"0000"];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down