 //
 //  EHFAuthenticator.swift
-//  EHFAuthenticator-Example
 //
 //  Created by Christopher Truman on 9/29/14.
 //  Copyright (c) 2014 truman. All rights reserved.

        self.reason = ""
    }
    
    class func canAuthenticateWithError() throws{
        let error: NSError! = NSError(domain: "Migrator", code: 0, userInfo: nil)
        if ((NSClassFromString("LAContext")) != nil){
            if (EHFAuthenticator.sharedInstance.context.canEvaluatePolicy(EHFAuthenticator.sharedInstance.policy, error: nil)){
                return
            }
            throw error
        }
        throw error
    }
    
    func authenticateWithSuccess(success: EHFCompletionBlock, failure: EHFAuthenticationErrorBlock){
        self.context = LAContext()
        if (self.useDefaultFallbackTitle) {
            self.context.localizedFallbackTitle = self.fallbackButtonTitle as String;
        }else if (self.hideFallbackButton){
            self.context.localizedFallbackTitle = "";
        }
        if (self.context.canEvaluatePolicy(policy, error: nil)) {
            self.context.evaluatePolicy(policy, localizedReason:
                reason as String, reply:{ authenticated, error in
                if (authenticated) {
                    dispatch_async(dispatch_get_main_queue(), {success()})
                } else {
                    dispatch_async(dispatch_get_main_queue(), {failure(error!.code)})
                }
            })
        } else {
            failure(0)
        }
    }
}

typealias EHFCompletionBlock = Void ->()
typealias EHFAuthenticationErrorBlock = Int -> ()


class EHFAuthenticator : NSObject {
    
