Touch ID is a new public API on IOS8, for detailed introduction and usage can be seen in the Cocoachina of these two articles: up and down, in this article does not repeat.
The effect I need in the app is that if Touch ID verification passes, the page is push to the next Viewcontroller, otherwise the digital password input box for this view is Becomefirstresponder. People who have studied Touch ID should know that this code will probably do this:
1Lacontext *context =[[Lacontext alloc] init];2Nserror *error;3 4BOOL Canuse = [Context canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics error:&ERROR];5 if(canuse) {6 [Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics7Localizedreason:@"use Touch ID to open"
8reply:^ (BOOL success, Nserror *authenticationerror) {9 if(Success) {Ten //Push View One}Else { A //Popup input Box - } - }]; the}
I did it at first, and found that after the verification is complete, the interface will be stuck for more than 5 seconds before the next step, whether or not it succeeds. This is obviously unscientific, and then take a closer look at the description of the method, search on the internet, and finally, with the help of StackOverflow to understand. The result of one night's time ....
Let's take a look first -(void) EvaluatePolicy: (lapolicy) Policy Localizedreason: (NSString *) Localizedreason reply: (void (^) (BOOL Success, Nserror *error)) Reply This method describes the last parameter reply this block:
Reply
Reply block, executed when policy evaluation finishes. This block is evaluated on a private queue internal to the framework of an unspecified threading context. You must not call Canevaluatepolicy:error: in this block, because doing so could leads to deadlock.
Note the second sentence, probably meaning (English is not very good, light spray): This block will be in a private queue inside the framework to judge, and this framework is more in an indeterminate thread ... Say the simple point is, this block is not in the main thread to execute AH there are wood! The operation of the refresh interface must be placed in the main thread ah, there are wood! Aware of this and then look back to the online explanation including the official demo, all just in the reply nslog ah, println Ah, assign value to variables Ah, let me copy when completely ignore thread this thing ....
The next is easy to solve, or to define whether to verify the success of the BOOL flag, in the reply to determine the assignment, and then immediately after the method to judge flag to carry out the next step, or directly point, put the operation of reply in the main thread, shape as
1 [Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics2Localizedreason:@"use Touch ID to open"
3reply:^ (BOOL success, Nserror *authenticationerror) {4Dispatch_async (Dispatch_get_main_queue (), ^{5 if(Success) {6 //Push7}Else {8 //pop-up input box9 }Ten }); One}];
Resolves an issue in which the interface "has been stuck for a long time" in the callback using the Touch ID API