ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • iOS Device PassCode Enabled check
    개발/iOS 2021. 6. 4. 10:43

    iOS 장치에 암호 걸려있는지 안걸려있는지 체크하는 로직

     

    import LocalAuthentication

     

    func isEnabledPasscode()-> Bool {

            let context = LAContext()

            var error:NSError?

            

            let passcodeEnabled = context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)

            

            if (error != nil) {

                // error

                return false

            } else if (passcodeEnabled) {

                // passcode set

                return true

            } else {

                // passcode is not set

                return false

            }

    }

     

     

    /// Class that represents an authentication context.

    ///

    /// @discussion This context can be used for evaluating policies.

    ///

    /// @see LAPolicy

    API_AVAILABLE(macos(10.10), ios(8.0), watchos(3.0), tvos(10.0))

    @interface LAContext : NSObject

     

    /// Determines if a particular policy can be evaluated.

    ///

    /// @discussion Policies can have certain requirements which, when not satisfied, would always cause

    ///             the policy evaluation to fail - e.g. a passcode set, a fingerprint

    ///             enrolled with Touch ID or a face set up with Face ID. This method allows easy checking

    ///             for such conditions.

    ///

    ///             Applications should consume the returned value immediately and avoid relying on it

    ///             for an extensive period of time. At least, it is guaranteed to stay valid until the

    ///             application enters background.

    ///

    /// @warning    Do not call this method in the reply block of evaluatePolicy:reply: because it could

    ///             lead to a deadlock.

    ///

    /// @param policy Policy for which the preflight check should be run.

    ///

    /// @param error Optional output parameter which is set to nil if the policy can be evaluated, or it

    ///              contains error information if policy evaluation is not possible.

    ///

    /// @return YES if the policy can be evaluated, NO otherwise.

    - (BOOL)canEvaluatePolicy:(LAPolicy)policy error:(NSError * __autoreleasing *)error __attribute__((swift_error(none)))

        API_AVAILABLE(macos(10.10), ios(8.0), watchos(3.0), tvos(10.0));

Designed by Tistory.