本文介绍了检测 Secure Enclave 在当前设备上是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a certain way to detect if storing in Secure Enclave is available on current device?

推荐答案

这是另一个解决方案:

Device.h

#import <Foundation/Foundation.h>

@interface Device : NSObject

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

@end

Device.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 中的解决方案,请参考此链接.

If you want solution in Swift 4, then refer this link.

解决方案在 Swift 4 中

这篇关于检测 Secure Enclave 在当前设备上是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 22:35