標籤:指紋識別 ios8
跟想象的一樣,iOS 8中的指紋識別使用起來還是很方便的,只需要一個介面就能搞定,螢幕上彈出一個模態的框,跟app store上的一樣。
直接上代碼吧,下面代碼拷貝自Apple的官方文檔。
需要添加LocalAuthentication.framework庫,注意只有真機才有這個庫,模擬器沒有
#import "LocalAuthentication/LAContext.h" LAContext *myContext = [[LAContext alloc] init]; NSError *authError = nil; NSString *myLocalizedReasonString = @"請輸入指紋"; if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString reply:^(BOOL success, NSError *error) { if (success) { // User authenticated successfully, take appropriate action } else { // User did not authenticate successfully, look at error and take appropriate action } }]; } else { // Could not evaluate policy; look at authError and present an appropriate message to user }
效果:MyAddressBook 是我的app名字,“請輸入指紋”是代碼中的字串
還是很簡單的。