0
我一直在寫一個嵌套函數,它接受touchID的原因字符串和一個布爾值(如果應該顯示或不顯示)。這是我的代碼基本觸摸ID實現
import UIKit
import LocalAuthentication
class XYZ : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
presentTouchID(reasonToDsiplay: "Are you the owner?", true) //ERROR: Expression resolves to an unused function
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func presentTouchID(reasonToDsiplay reason: String, _ shouldShow: Bool) -> (Bool) ->(){
let reason1 = reason
let show = shouldShow
let long1 = { (shoudlShow: Bool) ->() in
if show{
let car = LAContext()
let reason = reason1
guard car.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: nil) else {return}
car.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {(success, error) in
guard error != nil else {return}
dispatch_async(dispatch_get_main_queue(), { Void in
print("Kwaatle")
})
}
}
else{
print("Mah")
}
}
return long1
}
}
當我做 func viewDidLoad()
presentTouchID(reasonToDsiplay: "Are you the owner?", true)
我得到一個錯誤說
表達式解析爲一個未使用的功能。
我在做什麼錯?
而@ luk2302,這也可以看作是一個完成處理程序正確刪除布爾作爲參數? – Dershowitz123
@ Dershowitz123是的,它是一個完成處理程序。 – luk2302
完美。這是否也是一個同步過程?因爲我讀過同步過程凍結了用戶界面?我是我錯了? @ luk2302? – Dershowitz123