From 7c86143dbaebb8e9459380ed879e9048243505dc Mon Sep 17 00:00:00 2001 From: Duc Do Date: Wed, 17 Jan 2018 14:06:22 +0100 Subject: [PATCH 1/5] moved touch ID button to support iPhone X --- PasscodeLock/Views/PasscodeLockView.xib | 38 ++++++++++++++++--------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/PasscodeLock/Views/PasscodeLockView.xib b/PasscodeLock/Views/PasscodeLockView.xib index 694aaf33..2335da5a 100644 --- a/PasscodeLock/Views/PasscodeLockView.xib +++ b/PasscodeLock/Views/PasscodeLockView.xib @@ -1,5 +1,5 @@ - + @@ -328,23 +328,34 @@ - + + + + + + + + + + + + @@ -355,7 +366,7 @@ - + @@ -387,10 +398,10 @@ + - @@ -402,6 +413,7 @@ + From 59ab6da82c0f0d21d21779fdefab5f4e8664245a Mon Sep 17 00:00:00 2001 From: Duc Do Date: Wed, 17 Jan 2018 14:40:18 +0100 Subject: [PATCH 2/5] changed backgroundcolor to clear --- PasscodeLock/Views/PasscodeLockView.xib | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PasscodeLock/Views/PasscodeLockView.xib b/PasscodeLock/Views/PasscodeLockView.xib index 2335da5a..339d3782 100644 --- a/PasscodeLock/Views/PasscodeLockView.xib +++ b/PasscodeLock/Views/PasscodeLockView.xib @@ -333,10 +333,10 @@ - + - From 1580fffcfb37a42fac3b31467a7fc03a9095b5de Mon Sep 17 00:00:00 2001 From: Duc Do Date: Thu, 18 Jan 2018 10:29:06 +0100 Subject: [PATCH 3/5] added support for FaceID --- PasscodeLock/Base.lproj/Localize.strings | 1 + PasscodeLock/PasscodeLockViewController.swift | 17 ++++++++++++++++- PasscodeLock/de.lproj/Localize.strings | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/PasscodeLock/Base.lproj/Localize.strings b/PasscodeLock/Base.lproj/Localize.strings index 25926802..1c83f62c 100644 --- a/PasscodeLock/Base.lproj/Localize.strings +++ b/PasscodeLock/Base.lproj/Localize.strings @@ -35,3 +35,4 @@ "Cancel" = "Cancel"; "Delete" = "Delete"; "UseTouchId" = "Use TouchID"; +"UseFaceId" = "Use FaceID"; diff --git a/PasscodeLock/PasscodeLockViewController.swift b/PasscodeLock/PasscodeLockViewController.swift index 63117e3a..0fbfb8a0 100644 --- a/PasscodeLock/PasscodeLockViewController.swift +++ b/PasscodeLock/PasscodeLockViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import LocalAuthentication open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegate { @@ -119,8 +120,22 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat self.titleLabel?.textColor = self.customTintColor self.descriptionLabel?.text = passcodeLock.state.description self.touchIDButton?.isHidden = !passcodeLock.isTouchIDAllowed - self.touchIDButton?.setTitle((self.stringsToShow?.useTouchID ?? localizedStringFor("UseTouchId", comment: "")), for: UIControlState()) + + var useBiometrics: String = "" + if #available(iOS 11.0, *) { + let context = LAContext() + context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) + let bioType = context.biometryType + if (bioType == .touchID) { + useBiometrics = localizedStringFor("UseTouchId", comment: "") + } else if (bioType == .faceID) { + useBiometrics = localizedStringFor("UseFaceId", comment: "") + } + } + + self.touchIDButton?.setTitle((self.stringsToShow?.useTouchID ?? useBiometrics), for: UIControlState()) self.touchIDButton?.setTitleColor(self.customTintColor, for: UIControlState()) + self.passcodeButtons?.forEach({ (passcodeButton: PasscodeSignButton) in passcodeButton.tintColor = self.customTintColor }) diff --git a/PasscodeLock/de.lproj/Localize.strings b/PasscodeLock/de.lproj/Localize.strings index d0d12f90..a5f13fae 100644 --- a/PasscodeLock/de.lproj/Localize.strings +++ b/PasscodeLock/de.lproj/Localize.strings @@ -35,3 +35,4 @@ "Cancel" = "Abbrechen"; "Delete" = "Löschen"; "UseTouchId" = "TouchID verwenden"; +"UseFaceId" = "FaceID verwenden"; From ff0c391c1c9dff7af0a92bb61f62aa9a00225297 Mon Sep 17 00:00:00 2001 From: Duc Do Date: Thu, 18 Jan 2018 11:00:05 +0100 Subject: [PATCH 4/5] updated localized strings --- PasscodeLock.xcodeproj/project.pbxproj | 2 ++ PasscodeLock/Functions.swift | 4 +-- PasscodeLock/en.lproj/Localize.strings | 38 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 PasscodeLock/en.lproj/Localize.strings diff --git a/PasscodeLock.xcodeproj/project.pbxproj b/PasscodeLock.xcodeproj/project.pbxproj index 64d9b76c..eec2906d 100644 --- a/PasscodeLock.xcodeproj/project.pbxproj +++ b/PasscodeLock.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 281AA9201DB626E000908E23 /* Localize.strings in Resources */ = {isa = PBXBuildFile; fileRef = 281AA9221DB626E000908E23 /* Localize.strings */; }; + 4A57CCF92010A437006A7B80 /* Localize.strings in Resources */ = {isa = PBXBuildFile; fileRef = 281AA9221DB626E000908E23 /* Localize.strings */; }; 8F3B9D031E028815008CF18F /* PasscodeLockImages.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8F3B9D021E028815008CF18F /* PasscodeLockImages.xcassets */; }; C99EAF431B90B05700D61E1B /* PasscodeLock.h in Headers */ = {isa = PBXBuildFile; fileRef = C99EAF421B90B05700D61E1B /* PasscodeLock.h */; settings = {ATTRIBUTES = (Public, ); }; }; C99EAF4A1B90B05800D61E1B /* PasscodeLock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C99EAF3F1B90B05700D61E1B /* PasscodeLock.framework */; }; @@ -516,6 +517,7 @@ C9D3DF1D1B91AD11008561EB /* LaunchScreen.storyboard in Resources */, C9D3DF1A1B91AD11008561EB /* Assets.xcassets in Resources */, C9D3DF181B91AD11008561EB /* Main.storyboard in Resources */, + 4A57CCF92010A437006A7B80 /* Localize.strings in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PasscodeLock/Functions.swift b/PasscodeLock/Functions.swift index 48fec1bd..c7ba7509 100644 --- a/PasscodeLock/Functions.swift +++ b/PasscodeLock/Functions.swift @@ -13,8 +13,8 @@ func localizedStringFor(_ key: String, comment: String) -> String { let name = "Localize" let bundle = bundleForResource(name, ofType: "strings") - - return NSLocalizedString(key, tableName: name, bundle: bundle, comment: comment) + + return NSLocalizedString(key, tableName: name, bundle: bundle, value: "", comment: comment) } func bundleForResource(_ name: String, ofType type: String) -> Bundle { diff --git a/PasscodeLock/en.lproj/Localize.strings b/PasscodeLock/en.lproj/Localize.strings new file mode 100644 index 00000000..1c83f62c --- /dev/null +++ b/PasscodeLock/en.lproj/Localize.strings @@ -0,0 +1,38 @@ +/* + Localize.strings + PasscodeLock + + Created by Ramiro Ramirez on 18/10/16. + Copyright © 2016 Yanko Dimitrov. All rights reserved. +*/ + +/* Enter Passcode State */ +"PasscodeLockEnterTitle" = "Enter Passcode"; +"PasscodeLockEnterDescription" = "Enter your passcode to proceed."; + +/* Set Passcode State */ +"PasscodeLockSetTitle" = "Enter a Passcode"; +"PasscodeLockSetDescription" = "Choose your passcode."; + +/* Confirm Passcode State */ +"PasscodeLockConfirmTitle" = "Confirm Passcode"; +"PasscodeLockConfirmDescription" = "Enter the passcode again."; + +/* Change Passcode State */ +"PasscodeLockChangeTitle" = "Enter Old Passcode"; +"PasscodeLockChangeDescription" = "Enter your old passcode."; + +/* Passcode Mismatch State */ +"PasscodeLockMismatchTitle" = "Try again"; +"PasscodeLockMismatchDescription" = "Passcodes didn\'t match."; + +/* Touch ID Reason */ +"PasscodeLockTouchIDReason" = "Authentication required to proceed"; + +/* Touch ID Fallback Button */ +"PasscodeLockTouchIDButton" = "Enter Passcode"; + +"Cancel" = "Cancel"; +"Delete" = "Delete"; +"UseTouchId" = "Use TouchID"; +"UseFaceId" = "Use FaceID"; From 323880227bd4339deac5689a85774ced3318b266 Mon Sep 17 00:00:00 2001 From: Duc Do Date: Thu, 18 Jan 2018 11:50:24 +0100 Subject: [PATCH 5/5] improved FaceID support --- PasscodeLock/PasscodeLockPresenter.swift | 4 +++- PasscodeLock/PasscodeLockViewController.swift | 22 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/PasscodeLock/PasscodeLockPresenter.swift b/PasscodeLock/PasscodeLockPresenter.swift index 5ecbd8e3..cb7018a2 100644 --- a/PasscodeLock/PasscodeLockPresenter.swift +++ b/PasscodeLock/PasscodeLockPresenter.swift @@ -27,8 +27,9 @@ public struct StringsToBeDisplayed { public var cancel: String? public var delete: String? public var useTouchID: String? + public var useFaceID: String? - public init(passcodeLockEnterTitle: String?, passcodeLockEnterDescription: String?, passcodeLockSetTitle: String?, passcodeLockSetDescription: String?, passcodeLockConfirmTitle: String?, passcodeLockConfirmDescription: String?, passcodeLockChangeTitle: String?, passcodeLockChangeDescription: String?, passcodeLockMismatchTitle: String?, passcodeLockMismatchDescription: String?, passcodeLockTouchIDReason: String?, passcodeLockTouchIDButton: String?, cancel: String?, delete: String?, useTouchID: String?) { + public init(passcodeLockEnterTitle: String?, passcodeLockEnterDescription: String?, passcodeLockSetTitle: String?, passcodeLockSetDescription: String?, passcodeLockConfirmTitle: String?, passcodeLockConfirmDescription: String?, passcodeLockChangeTitle: String?, passcodeLockChangeDescription: String?, passcodeLockMismatchTitle: String?, passcodeLockMismatchDescription: String?, passcodeLockTouchIDReason: String?, passcodeLockTouchIDButton: String?, cancel: String?, delete: String?, useTouchID: String?, useFaceID: String?) { self.passcodeLockEnterTitle = passcodeLockEnterTitle self.passcodeLockEnterDescription = passcodeLockEnterDescription @@ -45,6 +46,7 @@ public struct StringsToBeDisplayed { self.cancel = cancel self.delete = delete self.useTouchID = useTouchID + self.useFaceID = useFaceID } } diff --git a/PasscodeLock/PasscodeLockViewController.swift b/PasscodeLock/PasscodeLockViewController.swift index 0fbfb8a0..7fdf570b 100644 --- a/PasscodeLock/PasscodeLockViewController.swift +++ b/PasscodeLock/PasscodeLockViewController.swift @@ -112,36 +112,34 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat } } - internal func updatePasscodeView() { + internal func updatePasscodeView() { self.customImageView?.image = self.customImage - self.titleLabel?.text = passcodeLock.state.title + self.titleLabel?.text = passcodeLock.state.title self.titleLabel?.font = self.font self.titleLabel?.textColor = self.customTintColor - self.descriptionLabel?.text = passcodeLock.state.description - self.touchIDButton?.isHidden = !passcodeLock.isTouchIDAllowed + self.descriptionLabel?.text = passcodeLock.state.description + self.touchIDButton?.isHidden = !passcodeLock.isTouchIDAllowed - var useBiometrics: String = "" + var useBiometrics: String = localizedStringFor("UseTouchId", comment: "") + var useBiomatricsToShow: String? = self.stringsToShow?.useTouchID if #available(iOS 11.0, *) { let context = LAContext() context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) let bioType = context.biometryType - if (bioType == .touchID) { - useBiometrics = localizedStringFor("UseTouchId", comment: "") - } else if (bioType == .faceID) { + if (bioType == .faceID) { useBiometrics = localizedStringFor("UseFaceId", comment: "") + useBiomatricsToShow = self.stringsToShow?.useFaceID } } - self.touchIDButton?.setTitle((self.stringsToShow?.useTouchID ?? useBiometrics), for: UIControlState()) - self.touchIDButton?.setTitleColor(self.customTintColor, for: UIControlState()) - + self.touchIDButton?.setTitle((useBiomatricsToShow ?? useBiometrics), for: UIControlState()) self.passcodeButtons?.forEach({ (passcodeButton: PasscodeSignButton) in passcodeButton.tintColor = self.customTintColor }) self.cancelDeleteButtonSetup() - } + } // MARK: - Events