This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
forked from yankodimitrov/SwiftPasscodeLock
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from moogle19/master
Specific RemovePasscodeState for better Passcode Removal
- Loading branch information
Showing
11 changed files
with
194 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// RemovePasscodeState.swift | ||
// PasscodeLock | ||
// | ||
// Created by Kevin Seidel on 06/10/16. | ||
// Copyright © 2016 Yanko Dimitrov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RemovePasscodeState: PasscodeLockStateType { | ||
let title: String | ||
let description: String | ||
let isCancellableAction = false | ||
var isTouchIDAllowed: Bool { return false } | ||
|
||
private var isNotificationSent = false | ||
|
||
fileprivate var incorrectPasscodeAttemptsKey = "incorrectPasscodeAttemps" | ||
private var incorrectPasscodeAttempts: Int { | ||
get { | ||
return UserDefaults.standard.integer(forKey: incorrectPasscodeAttemptsKey) | ||
} | ||
set { | ||
UserDefaults.standard.set(newValue, forKey: incorrectPasscodeAttemptsKey) | ||
} | ||
} | ||
|
||
init() { | ||
|
||
title = localizedStringFor("PasscodeLockEnterTitle", comment: "Enter passcode title") | ||
description = localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description") | ||
} | ||
|
||
mutating func accept(passcode: String, from lock: PasscodeLockType) { | ||
if lock.repository.check(passcode: passcode) { | ||
|
||
lock.repository.delete() | ||
|
||
lock.delegate?.passcodeLockDidSucceed(lock) | ||
|
||
incorrectPasscodeAttempts = 0 | ||
|
||
} else { | ||
|
||
incorrectPasscodeAttempts += 1 | ||
|
||
if incorrectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts { | ||
|
||
postNotification() | ||
} | ||
|
||
lock.delegate?.passcodeLockDidFail(lock) | ||
} | ||
} | ||
|
||
fileprivate mutating func postNotification() { | ||
|
||
guard !isNotificationSent else { return } | ||
|
||
NotificationCenter.default.post(name: Notification.Name(rawValue: PasscodeLockIncorrectPasscodeNotification), object: nil) | ||
|
||
isNotificationSent = true | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.