Code Monkey home page Code Monkey logo

cplockcontroller's Introduction

CPLockController

CPLockController is UIViewController subclass that allows users to set a 4 digit passcode or enter one.

http://chrispurcell.net

Using CPLockController in your project

  1. Add CPLockController.h/.m to your project.

  2. Import CPLockController.h to your class header

     #import "CPLockController.h"
    
  3. Make your class follow the CPLockControllerDelegate protocol:

     @interface SampleAppViewController : UIViewController <CPLockControllerDelegate>
    
  4. Implement CPLockControllerDelegate methods:

     #pragma mark CPLockControllerDelegate Methods
     
     - (void)lockControllerDidFinish:(NSString*)passcode {
     	//called when the controller is finished
     	//a passcode is passed only when setting a new code
     	if(passcode){
     		NSLog(@"new passcode: %@",passcode);
     	} else {
     		NSLog(@"passcode accepted!");
     	}
     }
     
     - (void)lockControllerDidCancel {
     	//called when user hits cancel button
     	NSLog(@"user cancelled auth");
     }
    
  5. For setting a new passcode:

     CPLockController *lockController = [[CPLockController alloc]initWithStyle:CPLockControllerTypeSet];
     lockController.delegate = self;
    
  6. For authorizing a user with a passcode:

     CPLockController *lockController = [[CPLockController alloc]initWithStyle:CPLockControllerTypeAuth];
     lockController.passcode = @"1234";  //this is the passcode the user needs to enter
     lockController.delegate = self;
    

6a. If using with an iPad, it is recommended to display using the UIModalPresentationFormSheet style lockController.modalPresentationStyle = UIModalPresentationFormSheet;

6b. If you want to delegate acceptance of the passcode to your own logic (e.g. comparing to a stored hash), implement the optional protocol: - (BOOL)lockController:(CPLockController *)lockController shouldAcceptPasscode:(NSString *)passcode;

  1. That's it! Optional customization: //Customize the navigation item title lockController.title = @"Passcode is 1234";

     //Customize the passcode prompt
     lockController.prompt = @"Please enter your passcode";
     
     //Show passcode during entry- default is YES
     lockController.hideCode = NO;
    
  2. If you need to localize the default prompts, they are located at the top of CPLockController.m

     #define kCPLCDefaultSetPrompt			@"Enter your new passcode"
     #define kCPLCDefaultAuthPrompt			@"Enter your passcode"
    
     #define kCPLCDefaultSetTitle			@"Set Passcode"
     #define kCPLCDefaultConfirmTitle		@"Confirm Passcode"
     #define kCPLCDefaultAuthTitle			@"Enter Passcode"
    
     #define kCPLCDefaultSetError			@"Passcodes did not match. Try again."
     #define kCPLCDefaultAuthError			@"Passcode incorrect. Try again."
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.