iOS8指纹识别TouchID

苹果在2014年6月3日的WWDC2014开幕式上推出了新版iOS8系统,界面上iOS8与iOS7相比变化不大,不过在功能方面进行了完善。iOS8通知中心更加强大,支持消息直接回复操作,并支持QuickType和第三方输入法。短信功能改进明显,支持群聊,发送语音、视频,分享地理位置等。从终端用户的角度看,iOS8的许多新功能早已出现在其他平台中。iOS8会向第三方软件开放TouchID访问,这意味着可以使用该感应器登陆银行应用等。

      第三方应用可以使用TouchID接口,意味着未来的很多应用都可以用指纹识别功能了。你可以选择Touch ID登陆第三方应用程序,不需要输入密码,你的指纹数据是被保护的,在没有被允许的情况下别的程序是访问不到它的。

                                 

      根据苹果的解释,一个单一的注册指纹与别人指纹出现随机匹配的概率为五万分之一。

      苹果声称“Secure Enclave”模块系统能够安全地管理并识别用户的指纹,并将用户的指纹信息独立地保存在别的系统中,同时通过加密内存和一个硬件随机数字密码发生器进行管理。

      每个“Secure Enclave”是单独设置的,不能访问系统其他部分的,拥有自己的独立的UID(唯一的ID),连苹果也不知道这些UID。当设备启动时,Touch ID会临时创建一个秘钥,与“Secure Enclave”的UID配合,对设备的内存空间进行加密。

      而在苹果发布的文件中,苹果对A7处理器进行指纹识别授权的描述是:A7和Touch ID之间通过一个串行外设接口总线进行通信。A7处理器将数据发到“Secure Enclave”,但并不对数据内容进行读取。加密和身份验证都是使用Touch ID和“Secure Enclave”之间的共享密钥。通信密钥交换使用双方提供的一个随机AES密钥,并随机建立会话密钥和使用AES-CCM传输加密。

      据了解:iPhone 5s中的指纹传感器检测到的表皮上突起的纹线。它检测到的不是用户手指外部的死皮指纹,这种指纹很容易被复制。iPhone 5s的指纹传感器利用射频信号,检测用户手指表面下方那一层皮肤的“活”指纹。如果手指与人的身体分离,那么传感器是无法检测到这种指纹的。所以用户不用担心自己的指纹被复制或盗窃之后,被用于解锁设备,因为传感器是无法识别这种“死”指纹的。


      最近研究了下iOS8的文档,对指纹识别了解了下,并下载了一个官方提供的Demo。但是

      NS_CLASS_AVAILABLE(10_10, 8_0)

      从这句中可以看出,要想使用TouchID的接口,电脑的mac系统必须是10.10的,手机iOS系统必须是8.0,所以为了这个Demo我也没有升级电脑系统(毕竟还不稳定)。但根据Demo中的代码和文档可以看出,TouchID的基本用法。

1.首先要使用TouchID,要先导入依赖包:LocalAuthentication.framework

2.检查设备是否能用TouchID,返回检查结果BOOL类型success:

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. LAContext *context = [[LAContext alloc] init];  
  2.     __block  NSString *msg;  
  3.     NSError *error;  
  4.     BOOL success;  
  5.       
  6.     // test if we can evaluate the policy, this test will tell us if Touch ID is available and enrolled  
  7.     success = [context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];  
  8.     if (success) {  
  9.         msg =[NSString stringWithFormat:NSLocalizedString(@"TOUCH_ID_IS_AVAILABLE", nil)];  
  10.     } else {  
  11.         msg =[NSString stringWithFormat:NSLocalizedString(@"TOUCH_ID_IS_NOT_AVAILABLE", nil)];  
  12.     }  

3.如果设备能使用TouchID,代码块中返回识别结果BOOL类型的success:

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. LAContext *context = [[LAContext alloc] init];  
  2.     __block  NSString *msg;  
  3.       
  4.     // show the authentication UI with our reason string  
  5.     [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"UNLOCK_ACCESS_TO_LOCKED_FATURE", nil) reply:  
  6.      ^(BOOL success, NSError *authenticationError) {  
  7.          if (success) {  
  8.              msg =[NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_SUCCESS", nil)];  
  9.          } else {  
  10.              msg = [NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_WITH_ERROR", nil), authenticationError.localizedDescription];  
  11.          }  
  12.      }];  

4.对于检查和识别的两个方法在 LocalAuthentication.framework/Headers/LAContext.h 中定义的:

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. /// Determines if a particular policy can be evaluated.  
  2. ///  
  3. /// @discussion Policies can have certain requirements which, when not satisfied, would always cause  
  4. ///             the policy evaluation to fail. Examples can be a passcode set or a fingerprint  
  5. ///             enrolled with Touch ID. This method allows easy checking for such conditions.  
  6. ///  
  7. ///             Applications should consume the returned value immediately and avoid relying on it  
  8. ///             for an extensive period of time. At least, it is guaranteed to stay valid until the  
  9. ///             application enters background.  
  10. ///  
  11. /// @warning    Do not call this method in the reply block of evaluatePolicy:reply: because it could  
  12. ///             lead to a deadlock.  
  13. ///  
  14. /// @param policy Policy for which the preflight check should be run.  
  15. ///  
  16. /// @param error Optional output parameter which is set to nil if the policy can be evaluated, or it  
  17. ///              contains error information if policy evaluation is not possible.  
  18. ///  
  19. /// @return YES if the policy can be evaluated, NO otherwise.  
  20. - (BOOL)canEvaluatePolicy:(LAPolicy)policy error:(NSError * __autoreleasing *)error;  
  21.   
  22. /// Evaluates the specified policy.  
  23. ///  
  24. /// @discussion Policy evaluation may involve prompting user for various kinds of interaction  
  25. ///             or authentication. Actual behavior is dependent on evaluated policy, device type,  
  26. ///             and can be affected by installed configuration profiles.  
  27. ///  
  28. ///             Be sure to keep a strong reference to the context while the evaluation is in progress.  
  29. ///             Otherwise, an evaluation would be canceled when the context is being deallocated.  
  30. ///  
  31. ///             The method does not block. Instead, the caller must provide a reply block to be  
  32. ///             called asynchronously when evaluation finishes. The block is executed on a private  
  33. ///             queue internal to the framework in an unspecified threading context. Other than that,  
  34. ///             no guarantee is made about which queue, thread, or run-loop the block is executed on.  
  35. ///  
  36. ///             Implications of successful policy evaluation are policy specific. In general, this  
  37. ///             operation is not idempotent. Policy evaluation may fail for various reasons, including  
  38. ///             user cancel, system cancel and others, see LAError codes.  
  39. ///  
  40. /// @param policy Policy to be evaluated.  
  41. ///  
  42. /// @param reply Reply block that is executed when policy evaluation finishes.  
  43. ///  
  44. /// @param localizedReason Application reason for authentication. This string must be provided in correct  
  45. ///                        localization and should be short and clear. It will be eventually displayed in  
  46. ///                        the authentication dialog subtitle. A name of the calling application will be  
  47. ///                        already displayed in title, so it should not be duplicated here.  
  48. ///  
  49. /// @param success Reply parameter that is YES if the policy has been evaluated successfully or NO if  
  50. ///                the evaluation failed.  
  51. ///  
  52. /// @param error Reply parameter that is nil if the policy has been evaluated successfully, or it contains  
  53. ///              error information about the evaluation failure.  
  54. ///  
  55. /// @warning localizedReason parameter is mandatory and the call will throw NSInvalidArgumentException if  
  56. ///          nil or empty string is specified.  
  57. ///  
  58. /// @see LAError  
  59. ///  
  60. /// Typical error codes returned by this call are:  
  61. /// @li          LAErrorUserFallback if user tapped the fallback button  
  62. /// @li          LAErrorUserCancel if user has tapped the Cancel button  
  63. /// @li          LAErrorSystemCancel if some system event interrupted the evaluation (e.g. Home button pressed).  
  64. - (void)evaluatePolicy:(LAPolicy)policy localizedReason:(NSString *)localizedReason reply:(void(^)(BOOL success, NSError *error))reply;  

欢迎小伙伴们对测试结果检验一下啊!

(转载请注明出处,谢谢!http://blog.csdn.net/yujianxiang666/article/details/35280025)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值