biometric
import "github.com/tangoui/tango/sys/biometric"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package biometric verifies the device owner with Face ID / Touch ID (iOS, macOS) or BiometricPrompt (Android 9+).
if err := biometric.Authenticate(a, biometric.Options{Reason: "Unlock your notes"}); err != nil {
// ErrCanceled, ErrFailed, ErrNotEnrolled, ErrLockedOut, ErrNotAvailable ...
}
iOS needs NSFaceIDUsageDescription in Info.plist (permission "biometric" in tan.json); without it Authenticate returns ErrNotConfigured instead of crashing. Android needs android.permission.USE_BIOMETRIC.
Functions return ErrUnsupported where the backend has no biometrics and tango.ErrNotRunning after the app quit. On Android call Authenticate from a goroutine, not from a main-thread callback.
常量
const (
None = platform.BiometryNone
TouchID = platform.BiometryTouchID // also Android fingerprint
FaceID = platform.BiometryFaceID // also Android face
OpticID = platform.BiometryOpticID
Other = platform.BiometryOther // available, kind not reported (Android)
)变量
var (
ErrUnsupported = platform.ErrUnsupported
ErrCanceled = platform.ErrCanceled
ErrFailed = platform.ErrAuthFailed
ErrNotAvailable = platform.ErrNotAvailable
ErrNotEnrolled = platform.ErrNotEnrolled
ErrLockedOut = platform.ErrLockedOut
ErrNotConfigured = platform.ErrNotConfigured
)函数
func Authenticate
func Authenticate(a *tango.App, o Options) errorAuthenticate shows the system prompt and waits; nil means the owner was verified.
func String
func String(k Kind) stringString names k: "none", "touchID", "faceID", "opticID", "biometric".
类型
Kind
type Kind = platform.BiometryKindKind is the biometry the device offers.
func Available
func Available(a *tango.App) (Kind, error)Available reports the device's biometry. When it is None, err says why (ErrNotAvailable, ErrNotEnrolled, ErrLockedOut).
Options
type Options struct {
Reason string // why the app asks; required on iOS/macOS
Title string // Android prompt title (default: the app name)
CancelTitle string // cancel button label; "" = system default
AllowPasscode bool // let the user fall back to the device passcode / PIN
// contains filtered or unexported fields
}Options configures the prompt.