Latest 0.0.1
Homepage https://github.com/farcaller/iphone-pinentry
License MIT Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Platforms ios
Frameworks UIKit
Authors

Pin Entry Classes

PinEntry is a small library that provides support for 4-digit pin code entries.

PENumpadView

Custom UIView that implements look&feel of iOS numpad keyboard with support for additional buttion in lower left corner.

When positioning the view, best frame is CGRectMake(0, 244, 320, 216). That’s the frame you get when using [[PENumpadView alloc] init];

Customizing PENumpadView

Use the property detailButton to specify the look of the optional button.

@property (nonatomic, readwrite, assign) NSUInteger detailButon
  • PEKeyboardDetailNone: no button (no events generated on tap)
  • PEKeyboardDetailDone: "DONE" button
  • PEKeyboardDetailNext: "NEXT" button
  • PEKeyboardDetailDot: "." button
  • PEKeyboardDetailEdit: "EDIT" button

Handling events

To handle key presses you need to implement PENumpadViewDelegate:

- (void)keyboardViewDidEnteredNumber:(int)num

Message is sent when digit key is tapped, num contains the value in 0..9 range.

- (void)keyboardViewDidBackspaced

Message is sent when backspace is tapped.

- (void)keyboardViewDidOptKey

Message is sent when detailButon is something other than PEKeyboardDetailNone and the lower left button is tapped.

If you define PINENTRY_KEYBOARD_SENDS_NOTIFICATIONS, each tap would also generate kPinEntryKeyboardEvent notification, where object is the PENumpadView, and detailInfo contains the key kPinEntryKeyboardCode with NSNumber value. 0..9 correspond to digit keys, -1 – lower left button, -2 – backspace.

PEViewController

The view controller that implements pin entry. You can use it as modal controller or present in navigation stack.

Customizing PEViewController

You can set up the prompt using prompt property:

@property (nonatomic, readwrite, copy) NSString *prompt

The promt is displaed just above the pin boxes.

Handling pin code entry

As soon as user enters 4 digits and taps "DONE", PEViewController sends pinEntryControllerDidEnteredPin: message to its delegate:

- (void)pinEntryControllerDidEnteredPin:(PEViewController *)controller

You can then get access to pin property that holds string representation of the pin code. Here’s a sample implementation of pin processing:

- (void)pinEntryControllerDidEnteredPin:(PEViewController *)controller
{
    if([controller.pin intValue] == 1234) {
        // ...
    }
}

Clearing input

You can use resetPin method to clear the current pin code, to make your PEViewController instance re-usable.

PinEntryController

A complete implementation of navigation stack, required to ask user for a pin code, update a pin code or create new pin code.

Verifying a pin code

- (void)verifyPin
{
    PEPinEntryController *c = [PEPinEntryController pinVerifyController];
    c.pinDelegate = self;
    [self presentModalViewController:c animated:YES];
}

- (BOOL)pinEntryController:(PEPinEntryController *)c shouldAcceptPin:(NSUInteger)pin
{
    // Verify the pin, return NO if it's incorrect. Otherwise hide the controller and return YES
    if(pin == mypin) {
        NSLog(@"Pin is valid!");
        return YES;
    } else {
        NSLog(@"Pin is not valid (use %d)!", mypin);
        return NO;
    }
}

Set the pin code (initial, without verify)

- (void)setPin
{
    PEPinEntryController *c = [PEPinEntryController pinCreateController];
    c.pinDelegate = self;
    [self presentModalViewController:c animated:YES];
}

- (void)pinEntryController:(PEPinEntryController *)c changedPin:(NSUInteger)pin
{
    // Update your info to new pin code
    NSLog(@"New pin is set to %d", pin);
    [self dismissModalViewControllerAnimated:YES];
}

Change pin code (with verification of current pin, can be cancelled)

- (void)chagePin
{
    PEPinEntryController *c = [PEPinEntryController pinChangeController];
    c.pinDelegate = self;
    [self presentModalViewController:c animated:YES];
}

- (BOOL)pinEntryController:(PEPinEntryController *)c shouldAcceptPin:(NSUInteger)pin
{
    // Verify the pin, return NO if it's incorrect
    if(pin == mypin) {
        NSLog(@"Pin is valid!");
        // Do NOT not hide pinChangeController yet
        return YES;
    } else {
        NSLog(@"Pin is not valid (use %d)!", mypin);
        return NO;
    }
}

- (void)pinEntryController:(PEPinEntryController *)c changedPin:(NSUInteger)pin
{
    // Update your info to new pin code
    NSLog(@"New pin is set to %d", pin);
    [self dismissModalViewControllerAnimated:YES];
}

- (void)pinEntryControllerDidCancel:(PEPinEntryController *)c
{
    NSLog(@"Pin change cancelled!");
    [self dismissModalViewControllerAnimated:YES];
}

TODO

  • Add i18n support
  • Add retina images

Latest podspec

{
    "name": "PinEntry",
    "version": "0.0.1",
    "summary": "iPhone pin entry controller and a custom numpad view.",
    "homepage": "https://github.com/farcaller/iphone-pinentry",
    "authors": {
        "Vlzcimif Pouzanov": "[email protected]"
    },
    "source": {
        "git": "https://github.com/farcaller/iphone-pinentry.git",
        "commit": "1d0f17e4d746881d3136c2933c43d694a9b3396f"
    },
    "description": "PinEntry is a small library that provides support for 4-digit pin code entries. See also https://github.com/farcaller/iphone-pinentry/blob/master/README.md.",
    "platforms": {
        "ios": null
    },
    "source_files": [
        "PinEntry",
        "PinEntry/Classes/**/*.{h,m,xib}"
    ],
    "resources": "PinEntry/Resources/*.png",
    "frameworks": "UIKit",
    "requires_arc": false,
    "license": {
        "type": "MIT",
        "text": "                   Permission is hereby granted, free of charge, to any person obtaining a copyn                   of this software and associated documentation files (the "Software"), to dealn                   in the Software without restriction, including without limitation the rightsn                   to use, copy, modify, merge, publish, distribute, sublicense, and/or selln                   copies of the Software, and to permit persons to whom the Software isn                   furnished to do so, subject to the following conditions:nn                   The above copyright notice and this permission notice shall be included inn                   all copies or substantial portions of the Software.nn                   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORn                   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,n                   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEn                   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERn                   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,n                   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INn                   THE SOFTWARE.n"
    }
}

Pin It on Pinterest

Share This