TOPasscodeViewController.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // TOPasscodeViewController.h
  3. //
  4. // Copyright 2017 Timothy Oliver. All rights reserved.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to
  8. // deal in the Software without restriction, including without limitation the
  9. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. // sell copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  21. // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #import <UIKit/UIKit.h>
  23. #import "TOPasscodeViewControllerConstants.h"
  24. #import "TOPasscodeSettingsViewController.h"
  25. #import "TOPasscodeView.h"
  26. NS_ASSUME_NONNULL_BEGIN
  27. @class TOPasscodeViewController;
  28. /**
  29. A delegate object in charge of validating the passcodes that the user has entered into the passcode
  30. view controller.
  31. */
  32. @protocol TOPasscodeViewControllerDelegate <NSObject>
  33. @optional
  34. /**
  35. Return YES if the user entered the expected PIN code. Return NO if it was incorrect.
  36. (For security reasons, it is safer to fetch the saved PIN code only when this method is called, and
  37. then discard it immediately. This is why the view controller does not directly store it.)
  38. */
  39. - (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code;
  40. /** The user tapped the 'Cancel' button. Any dismissing of confidential content should be done in here. */
  41. - (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController;
  42. /** The user successfully entered the correct code, as validated by `isCorrectCode:` */
  43. - (void)didInputCorrectPasscodeInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController;
  44. /** When available, the user tapped the 'Touch ID' button, or the view controller itself automatically initiated
  45. the Touch ID request on display. This method is where you should implement your
  46. own Touch ID validation logic. For security reasons, this controller does not implement the Touch ID logic itself. */
  47. - (void)didPerformBiometricValidationRequestInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController;
  48. /** Called when the pin view was resized as a result of the view controller being resized.
  49. You can use this to resize your custom header view if necessary.
  50. */
  51. - (void)passcodeViewController:(TOPasscodeViewController *)passcodeViewController didResizePasscodeViewToWidth:(CGFloat)width;
  52. @end
  53. /**
  54. A view controller that displays an interface for entering a user passcode.
  55. It may be presented modally over another view controller, requiring the user to enter
  56. the passcode correctly before they are able to proceed inside the application.
  57. */
  58. @interface TOPasscodeViewController : UIViewController
  59. /** A delegate object, in charge of verifying the PIN code entered by the user */
  60. @property (nonatomic, weak, nullable) id<TOPasscodeViewControllerDelegate> delegate;
  61. /** The type of passcode that is expected to be entered. */
  62. @property (nonatomic, readonly) TOPasscodeType passcodeType;
  63. /** Will show a 'Touch ID' or 'Face ID' (depending on `biometricType`) button if the user is allowed to log in that way. (Default is NO) */
  64. @property (nonatomic, assign) BOOL allowBiometricValidation;
  65. /** Will handle delete button press as delete last symbol (Default is YES) */
  66. @property (nonatomic, assign) BOOL handleDeletePress;
  67. /** Set the type of biometrics for this device to update the title of the biometrics button properly. */
  68. @property (nonatomic, assign) TOPasscodeBiometryType biometryType;
  69. /** If biometrics are available, automatically ask for it upon presentation (Default is NO) */
  70. @property (nonatomic, assign) BOOL automaticallyPromptForBiometricValidation;
  71. /** Optionally change the color of the title text label. */
  72. @property (nonatomic, strong, nullable) UIColor *titleLabelColor;
  73. /** Optionally change the tint color of the UI element that indicates input progress (eg the row of circles) */
  74. @property (nonatomic, strong, nullable) UIColor *inputProgressViewTintColor;
  75. /** Optionally enable or disable showing the lettering label of all keypad circle buttons. **/
  76. @property (nonatomic, assign) BOOL keypadButtonShowLettering;
  77. /** If the style isn't translucent, changes the tint color of the keypad circle button outlines. */
  78. @property (nonatomic, strong, nullable) UIColor *keypadButtonBackgroundTintColor;
  79. /** The color of the text elements in each keypad button */
  80. @property (nonatomic, strong, nullable) UIColor *keypadButtonTextColor;
  81. /** Optionally, the text color of the keypad button text when tapped. Animates back to the base color. */
  82. @property (nonatomic, strong, nullable) UIColor *keypadButtonHighlightedTextColor;
  83. /** The tint button of the accessory button views at the bottom of the keypad (ie 'Cance' etc) */
  84. @property (nonatomic, strong, nullable) UIColor *accessoryButtonTintColor;
  85. /** Controls the transluceny of the PIN background when the style has been set to translucent. */
  86. @property (nonatomic, readonly) UIVisualEffectView *backgroundEffectView;
  87. /** Opaque, background view when the style is opaque */
  88. @property (nonatomic, readonly) UIView *backgroundView;
  89. /** The keypad and accessory views that are displayed in the center of this view */
  90. @property (nonatomic, readonly) TOPasscodeView *passcodeView;
  91. /** The Touch ID button, visible if biometrics is enabled and `leftAccessoryButton` is nil. */
  92. @property (nonatomic, readonly) UIButton *biometricButton;
  93. /** The Cancel, visible if `rightAccessoryButton` is nil. */
  94. @property (nonatomic, readonly) UIButton *cancelButton;
  95. /** The left accessory button. Setting this will override the 'Touch ID' button. */
  96. @property (nonatomic, strong, nullable) UIButton *leftAccessoryButton;
  97. /** The right accessory button. Setting this will override the 'Cancel' button. */
  98. @property (nonatomic, strong, nullable) UIButton *rightAccessoryButton;
  99. @property (nonatomic, assign) CGFloat accessoryButtonsVerticalInset;
  100. /** Whether all of the content views are hidden or not, but the background translucent view remains.
  101. Useful for obscuring the content while the app is suspended. */
  102. @property (nonatomic, assign) BOOL contentHidden;
  103. /**
  104. Create a new instance of this view controller with the preset style and passcode type.
  105. @param type The type of passcode to enter (6-digit/numeric)
  106. */
  107. - (instancetype)initPasscodeType:(TOPasscodeType)type allowCancel:(BOOL)cancel;
  108. /**
  109. Hide everything except the background translucency view.
  110. @param hidden Whether the content is hidden or not.
  111. @param animated The content will play a crossfade animation.
  112. */
  113. - (void)setContentHidden:(BOOL)hidden animated:(BOOL)animated;
  114. @end
  115. NS_ASSUME_NONNULL_END
  116. //! Project version number for TOPasscodeViewController.
  117. FOUNDATION_EXPORT double TOPasscodeViewControllerVersionNumber;
  118. //! Project version string for TOPasscodeViewController.
  119. FOUNDATION_EXPORT const unsigned char TOPasscodeViewControllerVersionString[];