Skip to content
This repository was archived by the owner on Mar 15, 2020. 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
6 changes: 5 additions & 1 deletion SampleApp/SAViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#import <UIKit/UIKit.h>

@interface SAViewController : UIViewController
@interface SAViewController : UIViewController {
NSString *code;
}

@property (atomic, copy) NSString *code;

- (IBAction)setPIN;
- (IBAction)checkPIN;
Expand Down
27 changes: 22 additions & 5 deletions SampleApp/SAViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,31 @@

@implementation SAViewController

@synthesize code;

- (void)viewDidLoad {
// Set default code
self.code = @"0187";
}

- (IBAction)setPIN {
GCPINViewController *PIN = [[GCPINViewController alloc]
initWithNibName:nil
bundle:nil
mode:GCPINViewControllerModeCreate];
PIN.messageText = @"Enter a passcode";
PIN.confirmText = @"Confirm your passcode";
PIN.errorText = @"The passcodes do not match";
PIN.title = @"Set Passcode";
PIN.verifyBlock = ^(NSString *code) {
NSLog(@"setting code: %@", code);
PIN.verifyBlock = ^(NSString *newCode) {
NSLog(@"setting code: %@", newCode);
self.code = newCode;
return YES;
};
PIN.cancelBlock = ^ {
NSLog(@"Cancelling PIN setting");
};
PIN.cancelButtonVisible = YES;
[PIN presentFromViewController:self animated:YES];
[PIN release];
}
Expand All @@ -36,10 +49,14 @@ - (IBAction)checkPIN {
PIN.messageText = @"Enter your passcode";
PIN.errorText = @"Incorrect passcode";
PIN.title = @"Enter Passcode";
PIN.verifyBlock = ^(NSString *code) {
NSLog(@"checking code: %@", code);
return [code isEqualToString:@"0187"];
PIN.verifyBlock = ^(NSString *enteredCode) {
NSLog(@"checking code: %@", enteredCode);
return [enteredCode isEqualToString:self.code];
};
PIN.cancelBlock = ^ {
NSLog(@"Cancelling verification");
};
PIN.cancelButtonVisible = YES;
[PIN presentFromViewController:self animated:YES];
[PIN release];
}
Expand Down
16 changes: 16 additions & 0 deletions pinview/GCPINViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum {
} GCPINViewControllerMode;

typedef BOOL (^GCPasscodeVerifyBlock) (NSString *code);
typedef void (^GCPasscodeCancelBlock) ();

/*

Expand All @@ -49,6 +50,12 @@ typedef BOOL (^GCPasscodeVerifyBlock) (NSString *code);
*/
@property (nonatomic, copy) NSString *messageText;

/*

Set the text to display below the input area when confirming a set PIN
*/
@property (nonatomic, copy) NSString *confirmText;

/*

Set the text to display below the input area when the passcode fails
Expand All @@ -70,6 +77,13 @@ typedef BOOL (^GCPasscodeVerifyBlock) (NSString *code);
*/
@property (nonatomic, copy) GCPasscodeVerifyBlock verifyBlock;

/*

Called when cancelling out of passcode entry or verification.

*/
@property (nonatomic, copy) GCPasscodeCancelBlock cancelBlock;

/*

Refer to `GCPINViewControllerMode`. This can only be set through the
Expand Down Expand Up @@ -103,5 +117,7 @@ typedef BOOL (^GCPasscodeVerifyBlock) (NSString *code);
@property (nonatomic, retain) IBOutlet UILabel *messageLabel;
@property (nonatomic, retain) IBOutlet UILabel *errorLabel;
@property (nonatomic, retain) IBOutlet UITextField *inputField;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelButton;
@property (nonatomic, assign) BOOL cancelButtonVisible;

@end
41 changes: 39 additions & 2 deletions pinview/GCPINViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ @implementation GCPINViewController
@synthesize errorLabel = __errorLabel;
@synthesize inputField = __inputField;
@synthesize messageText = __messageText;
@synthesize confirmText = __confirmText;
@synthesize errorText = __errorText;
@synthesize labels = __labels;
@synthesize mode = __mode;
@synthesize text = __text;
@synthesize verifyBlock = __verifyBlock;
@synthesize cancelBlock = __cancelBlock;
@synthesize cancelButton = __cancelButton;
@synthesize cancelButtonVisible = __cancelButtonVisible;

#pragma mark - object methods
- (id)initWithNibName:(NSString *)nib bundle:(NSBundle *)bundle mode:(GCPINViewControllerMode)mode {
Expand Down Expand Up @@ -85,10 +89,13 @@ - (void)dealloc {
self.errorLabel = nil;
self.inputField = nil;
self.messageText = nil;
self.confirmText = nil;
self.errorText = nil;
self.labels = nil;
self.text = nil;
self.verifyBlock = nil;
self.cancelBlock = nil;
self.cancelButton = nil;

// super
[super dealloc];
Expand Down Expand Up @@ -129,11 +136,22 @@ - (void)dismiss {
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
});
}
- (void)cancel {
__dismiss = YES;
if ( self.cancelBlock != nil ) {
self.cancelBlock();
}
[self dismissModalViewControllerAnimated:YES];
}

#pragma mark - view lifecycle
- (void)viewDidLoad {
[super viewDidLoad];


// wire up cancel button
self.cancelButton.target = self;
self.cancelButton.action = @selector(cancel);

// setup labels list
self.labels = [NSArray arrayWithObjects:
self.fieldOneLabel,
Expand All @@ -158,6 +176,11 @@ - (void)viewDidLoad {
[self.inputField becomeFirstResponder];

}

- (void)viewWillAppear:(BOOL)animated {
self.navigationItem.leftBarButtonItem = self.cancelButtonVisible ? self.cancelButton : nil;
}

- (void)viewDidUnload {
[super viewDidUnload];
self.fieldOneLabel = nil;
Expand All @@ -169,6 +192,7 @@ - (void)viewDidUnload {
self.inputField = nil;
self.labels = nil;
self.text = nil;
self.cancelButton = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Expand All @@ -190,6 +214,10 @@ - (void)setErrorText:(NSString *)text {
__errorText = [text copy];
self.errorLabel.text = __errorText;
}
- (void)setCancelButtonVisible:(BOOL)cancelButtonVisible {
__cancelButtonVisible = cancelButtonVisible;
self.navigationItem.leftBarButtonItem = cancelButtonVisible ? self.cancelButton : nil;
}

#pragma mark - text field methods
- (void)textDidChange:(NSNotification *)notif {
Expand All @@ -200,14 +228,23 @@ - (void)textDidChange:(NSNotification *)notif {
if (self.mode == GCPINViewControllerModeCreate) {
if (self.text == nil) {
self.text = self.inputField.text;

// Display confirm text if it's been set
if ( self.confirmText != nil ) {
self.messageLabel.text = self.confirmText;
}

[self resetInput];
}
else {
if ([self.text isEqualToString:self.inputField.text] &&
self.verifyBlock(self.inputField.text)) {
[self dismiss];
}
else {
else {
// Reinstate original message text
self.messageLabel.text = self.messageText;

[self wrong];
}
}
Expand Down
28 changes: 26 additions & 2 deletions pinview/GCPINViewController~ipad.xib
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBUITextField</string>
<string>IBUIBarButtonItem</string>
<string>IBUIImageView</string>
<string>IBUIView</string>
<string>IBUILabel</string>
Expand Down Expand Up @@ -240,7 +241,6 @@
<string key="NSFrame">{{20, 136}, {280, 21}}</string>
<reference key="NSSuperview" ref="898314207"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
Expand Down Expand Up @@ -331,6 +331,11 @@
</object>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
<object class="IBUIBarButtonItem" id="25667243">
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<int key="IBUIStyle">1</int>
<int key="IBUISystemItemIdentifier">1</int>
</object>
</array>
<object class="IBObjectContainer" key="IBDocument.Objects">
<array class="NSMutableArray" key="connectionRecords">
Expand Down Expand Up @@ -398,6 +403,14 @@
</object>
<int key="connectionID">33</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">cancelButton</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="25667243"/>
</object>
<int key="connectionID">35</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
Expand Down Expand Up @@ -499,6 +512,11 @@
<reference key="object" ref="812647999"/>
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">34</int>
<reference key="object" ref="25667243"/>
<reference key="parent" ref="0"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -519,19 +537,21 @@
<string key="23.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="24.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="32.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="34.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">33</int>
<int key="maxID">35</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">GCPINViewController</string>
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="cancelButton">UIBarButtonItem</string>
<string key="errorLabel">UILabel</string>
<string key="fieldFourLabel">UILabel</string>
<string key="fieldOneLabel">UILabel</string>
Expand All @@ -541,6 +561,10 @@
<string key="messageLabel">UILabel</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="cancelButton">
<string key="name">cancelButton</string>
<string key="candidateClassName">UIBarButtonItem</string>
</object>
<object class="IBToOneOutletInfo" key="errorLabel">
<string key="name">errorLabel</string>
<string key="candidateClassName">UILabel</string>
Expand Down
Loading