使用密码或TouchID锁定特定应用

时间:2015-06-16 13:41:13

标签: ios objective-c iphone

我想使用Passcode或TouchID锁定特定应用,例如facebook,whatsapp等,因此未经授权的用户无法访问我想要保护的应用。

我在网上找不到任何方法,不确定是否可以锁定任何特定的应用程序?

1 个答案:

答案 0 :(得分:1)

在App开始实现登录屏幕时,对于touchID(touchID是iOS8 +),您可以使用以下代码:

LAContext *context = [[LAContext alloc] init];
context.localizedFallbackTitle = @"Enter PIN";
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"PIN Authentication" reply:^(BOOL success, NSError *error) {
   if (success)
   {
      //success, let's get started!
   }
   else if (error.code == LAErrorUserCancel)
   {
     NSLog(@"Authentication failed: %@", @"TouchID authentication cancelled");               
   }
   else if (error.code == LAErrorAuthenticationFailed) 
   {
      NSLog(@"Authentication failed: %@", @"TouchID authentication failed");
   }
   else if (error.code == LAErrorUserFallback) 
   {
      NSLog(@"Authentication failed: %@", @"TouchID authentication pin authentification fallback selected");
   }
   else if (error.code == LAErrorSystemCancel) 
   {
      NSLog(@"Authentication failed: %@", @"Touch authentication was canceled by system (e.g. another application went to foreground).");                
   }
   else if (error.code == LAErrorPasscodeNotSet) 
   {
      NSLog(@"Authentication failed: %@", @"Touch authentication could not start, because passcode is not set on the device.");
   }
   else if (error.code == LAErrorTouchIDNotAvailable) 
   {
      NSLog(@"Authentication failed: %@", @"Touch authentication could not start, because Touch ID is not available on the device.");
   }
   else if (error.code == LAErrorTouchIDNotEnrolled) 
   {
      NSLog(@"Authentication failed: %@", @"Touch authentication could not start, because Touch ID has no enrolled fingers.");
   }
   else 
   {
      NSLog(@"Authentication failed: %@", @"Touch ID has not been setup or system has cancelled");                
   }
}];
相关问题