kwigbo

Adventures in iOS!

1 note

Passcode Entry Screen iOS

I was recently asked to create a passcode screen for Tumble Photo. Since there is adult content on tumblr, the user wanted the ability to lock down the app with a passcode. I googled for a bit, thinking that someone had to have already done this. No luck, so here is the results of what I came up with. This can be used to set the passcode as well as to authenticate the passcode. I tried to get it as close visually and functionally to the passcode screen in the settings app.

** Update **

The following category is required for this to work.

Hex UIColor Category

Get the Source!

The KLockScreenController is the only class that you will need to use directly. Here is an example of usage…

This sample will show a lock screen for login.

KLockScreenController *lockScreen = [[[KLockScreenController alloc] 
	initWithLock:NO shouldClearLock:NO] autorelease];
lockScreen.delegate = self;
lockScreen.view.frame = CGRectMake(0, 0, 320, 480);
[self presentModalViewController:lockScreen animated:YES];

This sample will show a lock screen for login and specify that it should disable the passcode.

KLockScreenController *lockScreen = [[[KLockScreenController alloc] 
	initWithLock:NO shouldClearLock:YES] autorelease];
lockScreen.view.frame = CGRectMake(0, 0, 320, 480);
lockScreen.delegate = self;
[self presentModalViewController:lockScreen animated:YES];

This sample will enable setting a passcode.

KLockScreenController *lockScreen = [[[KLockScreenController alloc] 
	initWithLock:YES shouldClearLock:YES] autorelease];
lockScreen.view.frame = CGRectMake(0, 0, 320, 480);
lockScreen.delegate = self;
[self presentModalViewController:lockScreen animated:YES];

These are the delegate methods which you will use to store and check the passcode.

// Return YES if passcode is correct
- (BOOL) didSubmitPassCode:(NSString *) code withClear:(BOOL) clear
{
	return YES;
}

// Store newly created passcode
- (void) didSubmitLock:(NSString *) code
{
	
}

As always, let me know how well it works for you and I am always open to suggestions for improvement.

Filed under tutorials

  1. kwigbo posted this