A simple introduction to fingerprint recognition in the iphone series, which began with the fingerprint recognition function from the 5S onwards, opened the interface for fingerprint verification at the time of iOS8. So we have to judge the model and the version of the system in the fingerprint identification application. The code below, the following need to pay special attention is actually the difference between lapolicydeviceownerauthentication and Lapolicydeviceownerauthenticationwithbiometrics, And the version of the detection system through [Uidevice Currentdevice].systemversion.floatvalue, determine if the device is available Touch ID is through Canevaluatepolicy:error: This method to make judgments. It is also important to note that the following verification of the success of the fingerprint is done by default in the sub-thread, so if we want to do the UI operation to go back to the main thread to execute. This function can be implemented using Dispatch_async (dispatch_queue_t _nonnull queue, ^{}), which is passed into the home queue. There is also we can according to Eror code to make some judgments, look at the user specifically for what causes the error, and then make the corresponding output.
- 1, determine whether the system version is greater than or equal to 8.0 if greater than equals, it means that fingerprint identification can be used
- if ([Uidevice currentdevice].systemversion.floatvalue>=8.0)
- {
- The ability to determine if fingerprint recognition can be used is only possible after 5S.
- Create a context for a La object
- Lacontext * context = [[Lacontext alloc]init];
- Determine if the device supports fingerprint identification
- Evaluate means to evaluate
- Policy represents a strategy
- Used to check if the current device is available TouchID
- if ([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:nil])
- {
- Lapolicydeviceownerauthentication if we three times the fingerprint input is wrong, it will pop up the password box, if you do not enter the password. There are two chances to verify fingerprints if they're
- The error will continue to eject the System password box so you can enter it if you do not enter the Touch ID and the lapolicydeviceownerauthenticationwithbiometrics will not eject the input system.
- Password box, enter three errors after the default does not do any processing, we can also re-click on the fingerprint recognition for input, but if you enter the error two times after the Touch ID will be locked
- Indicates that fingerprint recognition technology can be used
- [Context evaluatepolicy:lapolicydeviceownerauthentication localizedreason:@ "Please verify the fingerprint for payment" reply:^
- (BOOL success, Nserror * _nullable error) {
- The inside is executed in the sub-thread, so to update the UI, it must be back to the main thread to execute the
- Judging whether it is successful
- if (success)
- {
- NSLog (@ "%@", [Nsthread CurrentThread]);
- NSLog (@ "verify success");
- }
- Else
- {
- NSLog (@ "Verification failed");
- }
- NSLog (@ "%@", [Nsthread CurrentThread]);
- NSLog (@ "%@", error);
- if (Error)
- {
- if (error.code==-2)
- {
- Dispatch_async (Dispatch_get_main_queue (), ^{
- Uialertcontroller * VC = [Uialertcontroller alertcontrollerwithtitle:@ "Fingerprint verification Cancel" message:@ ""
- Preferredstyle:uialertcontrollerstylealert];
- Uialertaction * action = [uialertaction actionwithtitle:@ "Confirm" style:uialertactionstyledefault
- handler:^ (uialertaction * _nonnull action) {
- NSLog (@ "---------");
- }];
- Uialertaction * Action1 = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel
- handler:^ (uialertaction * _nonnull action) {
- NSLog (@ "hhhhhh");
- }];
- [VC addaction:action];
- [VC Addaction:action1];
- [Self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil];
- });
- }
- else if (error.code==-1)
- {
- Dispatch_async (Dispatch_get_main_queue (), ^{
- Uialertcontroller * VC = [Uialertcontroller alertcontrollerwithtitle:@ "fingerprint has been wrong 3 times" message:
- @ "You have two more chances" preferredstyle:uialertcontrollerstylealert];
- Uialertaction * action = [uialertaction actionwithtitle:@ "Confirm" style:uialertactionstyledefault
- handler:^ (uialertaction * _nonnull action) {
- NSLog (@ "---------");
- }];
- [VC addaction:action];
- [Self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil];
- });
- }
- }
- }];
- }
- }
- Else
- {
- NSLog (@ "Sorry, the system version is too Low");
- }
Copy CodeSummarize The above is a small part of the introduction of the iOS development of the fingerprint of the simple introduction, I hope that we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for your support! |