LTHPasscodeViewController
简单易用的 iOS 7 风格的 Passcode - 就是您在设置中更改 Passcode 时的样式。
如何使用
将 LTHPasscodeViewController
的内容拖到您的项目中,或者在 Podfile 中添加 pod 'LTHPasscodeViewController'
(推荐)。
如果您的应用程序使用扩展,需要在每个目标的 Prefix.pch
文件中定义 LTH_IS_APP_EXTENSION
- 如果存在,则通过
#define LTH_IS_APP_EXTENSION
- 或者在每个目标的构建设置中,进入
预处理器宏
,双击每个方案,点击出现的弹出窗口中的+
,添加LTH_IS_APP_EXTENSION
示例,在 application:didFinishLaunchingWithOptions
中调用
[LTHPasscodeViewController useKeychain:NO];
if ([LTHPasscodeViewController doesPasscodeExist]) {
if ([LTHPasscodeViewController didPasscodeTimerEnd])
[[LTHPasscodeViewController sharedUser] showLockScreenWithAnimation:YES
withLogout:NO
andLogoutTitle:nil];
}
- 支持简单(4位)和复杂密码。
- 支持 Touch ID 和 Face ID。如果您使用 Face ID,请确保将
NSFaceIDUsageDescription
添加到您的Info.plist
中。文档可以在 这里 找到(感谢 @mgod 在 #193 中提出的建议)。 - 默认情况下,数据保存在 Keychain 中。通过调用
[LTHPasscodeViewController useKeychain:NO]
后初始化并实现一些协议方法(与库使用的同名),支持自定义保存
- (void)passcodeViewControllerWillClose;
- (void)maxNumberOfFailedAttemptsReached;
- (void)passcodeWasEnteredSuccessfully;
- (void)logoutButtonWasPressed;
- (NSTimeInterval)timerDuration;
- (void)saveTimerDuration:(NSTimeInterval)duration;
- (NSTimeInterval)timerStartTime;
- (void)saveTimerStartTime;
- (BOOL)didPasscodeTimerEnd;
- (void)deletePasscode;
- (void)savePasscode:(NSString *)passcode;
- (NSString *)passcode;
// All of them fall back on the Keychain if they are not implemented, even if [LTHPasscodeViewController useKeychain:NO] was called, for flexibility over what and where you save.
// Do you only want to save the passcode in a different location and leave everything else in the Keychain? Call [LTHPasscodeViewController useKeychain:NO], but only implement -savePasscode:
- 作为模态或推入方式打开,用于更改、启用或禁用密码
/**
@param viewController The view controller where the passcode view controller will be displayed.
@param asModal Set to YES to present as a modal, or to NO to push on the current nav stack.
*/
- (void)showForEnablingPasscodeInViewController:(UIViewController *)viewController asModal:(BOOL)isModal;
- (void)showForDisablingPasscodeInViewController:(UIViewController *)viewController asModal:(BOOL)isModal;
- (void)showForChangingPasscodeInViewController:(UIViewController *)viewController asModal:(BOOL)isModal;
- 在窗口上显示锁定屏幕
- (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle;
// Example:
[[LTHPasscodeViewController sharedUser] showLockscreenWithAnimation:YES withLogout:NO andLogoutTitle:nil];
// Displayed with a slide up animation, which, combined with
// the keyboard sliding down animation, creates an "unlocking" impression.
- 在特定视图中显示锁定屏幕。与上面的方法类似,但大小和中心将由传入的视图决定。
- (void)showLockScreenOver:(UIView *)superview withAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString *)logoutTitle;
// Example:
[[LTHPasscodeViewController sharedUser] showLockscreenOver:popover withAnimation:YES withLogout:NO andLogoutTitle:nil];
- 进入前台和注销操作在类内部处理。
如果您正在使用故事板(Storyboard)并在启动时显示锁定屏幕,但行为异常,您可以尝试使用代码初始化您的故事板,如Ben在此问题中建议的(感谢您!)。
使用SFHFKeyChainUtils来保存密码到密钥链。我知道他已经不再支持它,但我2年前为ARC更新了它(在这些帮助下)并且我一直在使用它。'新'版本根本没有更新为ARC,因此我认为切换到它或任何其他库都没有理由。
欢迎联系我,或者如果您有任何不清楚、有错误或可以改进的地方,请提交问题。
使用此控件的应用
Expenses Planner、DigitalOcean Manager、LovelyHeroku、Flow Web Browser、Balance - Checkbook App、QIF Reader、Zee - Personal Finance、EZDiary、MEGA。
如果您使用此控件,非常希望听到您的意见!
许可证
采用MIT许可证。如果您需要不带版权声明的许可证,请随时联系我。