iOS8指纹识别代码例子

来源:互联网 发布:java搜索引擎lucene 编辑:程序博客网 时间:2024/06/13 10:29
  • 跟想象的一样,iOS 8中的指纹识别使用起来还是很方便的,只需要一个接口就能搞定,屏幕上弹出一个模态的框,跟app store上的一样。

    直接上代码吧,下面代码拷贝自Apple的官方文档。

    需要添加LocalAuthentication.framework库,注意只有真机才有这个库,模拟器没有

    view sourceprint?
    01.#import "LocalAuthentication/LAContext.h"
    02.LAContext *myContext = [[LAContext alloc] init];
    03.NSError *authError = nil;
    04.NSString *myLocalizedReasonString = @"请输入指纹";
    05. 
    06.if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
    07.[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
    08.localizedReason:myLocalizedReasonString
    09.reply:^(BOOL success, NSError *error) {
    10.if (success) {
    11.// User authenticated successfully, take appropriate action
    12.else {
    13.// User did not authenticate successfully, look at error and take appropriate action
    14.}
    15.}];
    16.else {
    17.// Could not evaluate policy; look at authError and present an appropriate message to user
    18.}

    效果如图所示:MyAddressBook 是我的app名字,“请输入指纹”是代码中的字符串


    还是很简单的。

0 0