2016-07-15 85 views
1

我正在將TouchID集成到我的應用中。出於安全原因,我允許用戶打開和關閉它。我希望它在用戶添加新指紋時自動關閉。 據蘋果,evaluatedPolicyDomainStateTouchID - 檢測添加的新指紋 - evaluatePolicyDomainState何時更改?

This property returns a value only when the canEvaluatePolicy(:error:) method succeeds for a biometric policy or the evaluatePolicy(:localizedReason:reply:) method is called and a successful Touch ID authentication is performed. Otherwise, nil is returned.

The returned data is an opaque structure. It can be used to compare with other values returned by this property to determine whether the database of authorized fingerprints has been updated. However, the nature of the change cannot be determined from this data.

不過,我添加了新的指紋和evaluatedPolicyDomainState保持不變。

關於如何確保evaluatedPolicyDomainState得到更新或者是否有任何其他方式檢查是否添加新指紋?

回答

8

所以經過幾個小時的掙扎之後,我終於找到了解決方案。

let context = LAContext() 
    context.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: nil) 

    if let domainState = context.evaluatedPolicyDomainState 
     where domainState == oldDomainState { 
     // Enrollment state the same 

    } else { 
     // Enrollment state changed 

    } 

每次添加或刪除指紋時,域狀態都會改變。您需要致電canEvaluatePolicy以更新evaluatedPolicyDomainState

+0

嗨克里斯蒂安,我們也有這個requiremnet在我們的app.Can你請告訴我應該分配給oldDomainState變量? – RXGangam

+0

當您第一次請求用戶設置touchID時,您將使用'context.evaluatePolicy'。如果成功,則獲取當前策略並將其保存到oldDomainState。 –

+0

我已使用kSecAccessControlTouchIDCurrentSet。現在它按預期工作。 – RXGangam

0

下面是將evaluatePolicyDomainState的數據值轉換爲字符串並將其存儲在鑰匙串中的解決方案。如果Touch ID有任何變化,那麼您只需比較評估策略域名狀態的值。

if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) { 
 
    if let domainState = context.evaluatedPolicyDomainState { 
 
     let bData = domainState.base64EncodedData() 
 
     if let decodedString = String(data: bData, encoding: .utf8) { 
 
      print("Decoded Value: \(decodedString)") 
 
     } 
 
    } 
 
}

注:我沒有測試的面部識別驗證碼,我相信它會爲這兩個工作。

相關問題