NSUserDefaults中记录了此项的值,显示时直接读取设置开关的开与关状态即可
开关事件处理
- (void)addTouchID {
LAContext*context = [[LAContextalloc]init];
__blockNSString*msg =nil;
NSError*error =nil;
BOOLabool;
if(IOS_VERSION<8.0) {
return;
}
//检查touch ID是否可用
abool = [contextcanEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometricserror:&error];
if(abool) {
[contextevaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometricslocalizedReason:NSLocalizedString(@"通过Home键验证已有手机指纹",nil)reply:^(BOOLsuccess,NSError*error) {
if(success) {
[[NSOperationQueuemainQueue]addOperationWithBlock:^{
[[NSUserDefaultsstandardUserDefaults]setBool:YESforKey:@"Unlock"];
[[NSUserDefaultsstandardUserDefaults]synchronize];
[[NSUserDefaultsstandardUserDefaults]setBool:YESforKey:TouchID];
[[NSUserDefaultsstandardUserDefaults]synchronize];
}];
}else{
switch(error.code) {
caseLAErrorUserFallback:
caseLAErrorUserCancel:
caseLAErrorSystemCancel:
default:
[[NSOperationQueuemainQueue]addOperationWithBlock:^{
self.switchView.on=NO;
[[NSUserDefaultsstandardUserDefaults]setBool:self.switchView.onforKey:TouchID];
[[NSUserDefaultsstandardUserDefaults]synchronize];
[[NSOperationQueuemainQueue]addOperationWithBlock:^{
[[NSUserDefaultsstandardUserDefaults]setBool:NOforKey:TouchID];
[[NSUserDefaultsstandardUserDefaults]synchronize];
}];
}];
break;
}
msg = [NSStringstringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_WITH_ERROR",nil)];
}
}];
}
else{
[selfshowAlertViewWithMessage:@"touchID is unavailable!"];
self.switchView.on=NO;
[[NSUserDefaultsstandardUserDefaults]setBool:self.switchView.onforKey:TouchID];
[[NSUserDefaultsstandardUserDefaults]synchronize];
}
}
网友评论