방법: 기기 비밀번호 입력 요청하기

업데이트 날짜 21. 3월 2026 작성자 Jan Bunk


사용자가 앱을 열 때 기기 암호가 아닌 별도의 암호를 요청하는 완성된 솔루션을 찾고 있다면 암호 보호 기능을 확인해 보세요.

뛰어난 사용성을 유지하면서 앱의 보안을 강화하고 싶으신가요? 로컬 인증이 좋은 방법일 수 있어요. 이 문서에서는 사용자가 앱의 특정 부분에 접근하기 전에 기기 PIN, 지문 또는 Face ID를 입력하도록 요청하는 방법을 안내해 드려요.

기능 활성화하기

권한 설정에서 생체 인식 권한을 활성화해 주세요. 그렇지 않으면 이 기능이 일부만 작동하거나(Face ID 사용 불가) 예상치 못한 방식으로 작동하지 않을 수 있어요.

JavaScript 함수 사용하기

다음의 executeWhenAppReady() 함수를 확인해 보세요. 앱 도우미 스크립트예요.. 이 함수는 앱이 준비되기 전이나 웹사이트가 일반 브라우저에서 로드되었을 때 웹사이트에서 앱과 상호작용을 시도하지 않도록 해줘요(ReferenceError, 함수가 정의되지 않음).

requestLocalAuthentication

이 함수를 사용해 사용자에게 인증을 요청하세요.

인증에 성공하면 이 함수는 불리언 결과가 포함된 객체를 반환해요. 인증 요청이 취소되거나 기기에서 인증을 계속할 수 없으면 문자열 오류 코드가 대신 발생해요.


<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>
    
2026년 3월 21일 이전에 마지막으로 업데이트된 앱을 위한 마이그레이션

이전 앱 버전에서는 여전히 NotAvailable, PasscodeNotSet, LockedOut, PermanentlyLockedOut과 같은 오류 문자열을 처리하고 있을 수 있어요.

  • NotAvailable은 더 이상 하나의 특정 상황을 나타내지 않아요. 일반적으로 noCredentialsSet, uiUnavailable 또는 unknownError로 변경돼요.
  • PasscodeNotSet은 이제 noCredentialsSet이에요.
  • LockedOut과 PermanentlyLockedOut은 더 이상 발생하지 않는 것으로 보여요.
  • UserCancelled은 이제 userCanceled예요.
  • auth_in_progress는 이제 authInProgress예요.
  • no_activity와 no_fragment_activity는 이제 uiUnavailable이에요.