iOS8 check if device has Touch ID

后端 未结 5 732
不思量自难忘°
不思量自难忘° 2021-02-12 23:50

LAContext has method to check if device can evaluate touch ID and gives error message. Problem is that same error message \"LAErrorPasscodeNotSet\" is given by system in two cas

5条回答
  •  轮回少年
    2021-02-13 00:21

    Maybe you could write your own method to check which device are you running on, because if returned error is the same, it would be hard to figure out exactly if Touch ID is supported. I would go with something like this:

    int sysctlbyname(const char *, void *, size_t *, void *, size_t);
    
    - (NSString *)getSysInfoByName:(char *)typeSpecifier
    {
        size_t size;
        sysctlbyname(typeSpecifier, NULL, &size, NULL, 0);
    
        char *answer = malloc(size);
        sysctlbyname(typeSpecifier, answer, &size, NULL, 0);
    
        NSString *results = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
    
        free(answer);
        return results;
    }
    
    - (NSString *)modelIdentifier
    {
        return [self getSysInfoByName:"hw.machine"];
    }
    

    After having the model identifier, I would just check if model identifier equals is one of the models that support Touch ID:

    - (BOOL)hasTouchID
    {
        NSArray *touchIDModels = @[ @"iPhone6,1", @"iPhone6,2", @"iPhone7,1", @"iPhone7,2", @"iPad5,3", @"iPad5,4", @"iPad4,7", @"iPad4,8", @"iPad4,9" ];
    
        NSString *model = [self modelIdentifier];
    
        return [touchIDModels containsObject:model];
    }
    

    The array contains all model ID's which support Touch ID, which are:

    • iPhone 5s
    • iPhone 6
    • iPhone 6+
    • iPad Air 2
    • iPad Mini 3

    The only downside of this method is that once new devices are released with Touch ID, the model array will have to be updated manually.

提交回复
热议问题