I’m starting a new app, and I’d like to know how to require a password to open it.
I was considering a UIActionSheet in the application didFinishLaunchingWithOptions method of the app delegate implementation file, but am unsure how to go about doing so. I’m going to keep trying though.
Found this video, which seems pretty helpeful.
Now I’ve got my UIActionSheet to pop up displaying “Enter password,” and am trying to figure how to add a keypad to the action sheet.
I think you may have better luck using a full
UIViewControllerinstance instead of aUIActionSheet. Adding keyboard behavior to an action sheet will be difficult if not impossible.If you create a
UIViewControllersubclass, you can make your application delegate present it in-application:didFinishLaunchingWithOptions:. Assuming you’re using some sort ofUIViewControllerorUINaviagtionControllerfor your main interface, you could have the password view controller presented modally at startup usingUIViewController–presentModalViewController:animated:.Once you have your password view controller, you’ll need to add a
UITextFieldfor password entry. Make the text field becomefirstResponder(by callingbecomeFirstResponderon it), and that will cause the keyboard to be displayed. You may also want to set thekeyboardAppearanceproperty on the text field to control how the keypad appears if for example you want to limit to a numeric PIN versus a full password. Setting thesecureTextEntryproperty may also be desirable to prevent the actual password from being display. See theUITextInputTraitsprotocol onUITextFieldfor both of those options.In order to make the app secure, you would create your password view controller so that it has no buttons or navigation options other than a “Submit” or “Login” type button. If the user enters the correct password, you dismiss the modal view controller and let them in. If they don’t know the password, their only choice is to tap the Home button to exit your application as they’d have no way to proceed beyond the modal view controller.