Skip to content

biometric ​

go
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.

常量 ​

go
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)
)

变量 ​

go
var (
	ErrUnsupported   = platform.ErrUnsupported
	ErrCanceled      = platform.ErrCanceled
	ErrFailed        = platform.ErrAuthFailed
	ErrNotAvailable  = platform.ErrNotAvailable
	ErrNotEnrolled   = platform.ErrNotEnrolled
	ErrLockedOut     = platform.ErrLockedOut
	ErrNotConfigured = platform.ErrNotConfigured
)

函数 ​

func Authenticate ​

go
func Authenticate(a *tango.App, o Options) error

Authenticate shows the system prompt and waits; nil means the owner was verified.

func String ​

go
func String(k Kind) string

String names k: "none", "touchID", "faceID", "opticID", "biometric".

类型 ​

Kind ​

go
type Kind = platform.BiometryKind

Kind is the biometry the device offers.

func Available ​

go
func Available(a *tango.App) (Kind, error)

Available reports the device's biometry. When it is None, err says why (ErrNotAvailable, ErrNotEnrolled, ErrLockedOut).

Options ​

go
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.

以 MIT 许可发布