gpt4 book ai didi

ios - 检测 Secure Enclave 在当前设备上是否可用

转载 作者:行者123 更新时间:2023-12-03 18:32:20 24 4
gpt4 key购买 nike

是否有某种方法可以检测当前设备上是否可以存储在 Secure Enclave 中?

最佳答案

这是另一个解决方案:

设备.h

#import <Foundation/Foundation.h>

@interface Device : NSObject

+(BOOL) hasSecureEnclave;
+(BOOL) isSimulator;
+(BOOL) hasBiometrics;

@end

设备.m
#import "Device.h"
#import <LocalAuthentication/LocalAuthentication.h>

@implementation Device

//To check that device has secure enclave or not
+(BOOL) hasSecureEnclave {
NSLog(@"IS Simulator : %d", [Device isSimulator]);
return [Device hasBiometrics] && ![Device isSimulator] ;
}

//To Check that this is this simulator
+(BOOL) isSimulator {
return TARGET_OS_SIMULATOR == 1;
}

//Check that this device has Biometrics features available
+(BOOL) hasBiometrics {

//Local Authentication Context
LAContext *localAuthContext = [[LAContext alloc] init];
NSError *error = nil;

/// Policies can have certain requirements which, when not satisfied, would always cause
/// the policy evaluation to fail - e.g. a passcode set, a fingerprint
/// enrolled with Touch ID or a face set up with Face ID. This method allows easy checking
/// for such conditions.
BOOL isValidPolicy = [localAuthContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];

if (isValidPolicy) {

if (@available(ios 11.0, *)){
if (error.code != kLAErrorBiometryNotAvailable){
isValidPolicy = true;
} else{
isValidPolicy = false;
}
}else{
if (error.code != kLAErrorTouchIDNotAvailable){
isValidPolicy = true;
}else{
isValidPolicy = false;
}
}
return isValidPolicy;
}
return isValidPolicy;
}

@end

如果您想要 Swift 4 中的解决方案,请引用此链接。

Solution in Swift 4

关于ios - 检测 Secure Enclave 在当前设备上是否可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41759967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com