Swift4 Day95:Touch ID iOS實作

Alice
Daily Swift
Published in
1 min readJan 17, 2019

--

2019.1.17 Touch ID iOS swift 實作

Touch ID App UI design

兩個 Viewcontroller ,中間有 Get Access to secret information 的 button ,如果 TouchID 成功就可以跳轉到第二頁。下面的紅色 Label 用來顯示error message。

Checking if a device can use Touch ID and dealing with errors

記得先 import LocalAuthentication,才有辦法用LAContext()

用模擬器開的狀況

這時候用模擬機開,就會偵測到無法使用Touch ID。這部分的程式碼要用實機測試。

Evaluate policy and dealing with errors

再確認機器可以使用 Touch ID 後,就可以用 evaluatePolicy 去判斷指紋跟資料庫中的指紋是否相同,並處理有 error 的狀況。

Setting up the fall back password

如果指紋讀取失敗的時候,可以給一個輸入密碼的 UIAlertController 搭配 textFields,輸入 alice so cute 還是可以進到第二頁。我隨便寫的啦,大家還是要依照自己的需求去設計。

--

--