Anleitung: Nach dem Gerätepasswort fragen

Aktualisiert am 21. März 2026 von Jan Bunk


Wenn du nach einer fertigen Lösung suchst, die ein benutzerdefiniertes Passwort (nicht das Gerätepasswort) anfordert, wenn ein Nutzer die App öffnet schau dir die die Passwortschutzfunktion an.

Willst du die Sicherheit deiner App verbessern und gleichzeitig die Benutzerfreundlichkeit beibehalten? Dann könnte die lokale Authentifizierung der richtige Weg sein. Diese Dokumentation zeigt dir, wie du die Nutzer deiner App auffordern kannst, ihre Geräte-PIN/Fingerabdruck/Gesichtserkennung einzugeben, bevor sie auf Teile deiner App zugreifen.

Aktivieren der Funktion

Aktiviere die biometrische Berechtigung in deinen Berechtigungseinstellungen. Andernfalls kann es sein, dass diese Funktion nur teilweise funktioniert (keine Face ID) oder auf unerwartete Weise ausfällt.

Verwendung der JavaScript-Funktion

Schau dir gerne auch die executeWhenAppReady() Funktion von unser App-Helfer-Skript. Es stellt sicher, dass deine Website nicht versucht, mit der App zu interagieren, bevor sie bereit ist oder wenn deine Website mit einem normalen Browser geladen wird (ReferenceError, Funktion ist nicht definiert).

requestLocalAuthentication

Benutze diese Funktion, um den Benutzer zur Authentifizierung aufzufordern.

The function returns an object with a boolean result on success. If the authentication prompt is canceled or the device cannot continue, it throws a string error code instead.


<script>
    try {
        // This message will be displayed to the user along with the prompt.
        let reason = "Please authenticate to access this part of the app";

        // Returns a boolean. True if the authentication was successful, false if the authentication challenge failed.
        // If the prompt is canceled or the device cannot continue, an error string is thrown instead.
        let authenticationResult = (await requestLocalAuthentication(reason))["result"];
    }
    catch (e) {
        switch(e) {
            case "userCanceled":
                // The user canceled the prompt and didn't authenticate.
                break;
            case "authInProgress":
                // Another authentication request is already running.
                break;
            case "noCredentialsSet":
                // No biometrics, PIN, password, or pattern is configured.
                break;
            case "systemCanceled":
                // The system interrupted the authentication attempt, for example when the app gets closed.
                break;

            // All the errors below should be very rare in practice:

            case "timeout":
                // The authentication prompt timed out.
                break;
            case "uiUnavailable":
                // The system cannot show the authentication prompt right now.
                break;
            case "deviceError":
                // A device-level error prevented authentication.
                break;
            case "unknownError":
                // An unknown error occurred.
                break;
            default:
                // Any other error
                break;
        }
    }
</script>
    
Migration for apps last updated before 21st of March 2026

Older app versions may still be handling error strings such as NotAvailable, PasscodeNotSet, LockedOut, and PermanentlyLockedOut.

  • NotAvailable is no longer one specific case. It will usually become noCredentialsSet, uiUnavailable, or unknownError.
  • PasscodeNotSet is now noCredentialsSet.
  • LockedOut and PermanentlyLockedOut don't seem to happen anymore.
  • UserCancelled is now userCanceled.
  • auth_in_progress is now authInProgress.
  • no_activity and no_fragment_activity are now uiUnavailable.