This commit is contained in:
Umer Khan
2015-10-06 13:36:09 -07:00
5 changed files with 52 additions and 27 deletions
+5 -1
View File
@@ -35,9 +35,13 @@
#define STRONGTYPE(x) __strong __typeof(x)
ORK_EXTERN NSBundle *ORKBundle() ORK_AVAILABLE_DECL;
ORK_EXTERN NSBundle *ORKDefaultLocaleBundle();
#define ORKDefaultLocalizedValue(key) \
[ORKDefaultLocaleBundle() localizedStringForKey:key value:@"" table:nil]
#define ORKLocalizedString(key, comment) \
[ORKBundle() localizedStringForKey:(key) value:@"" table:nil]
[ORKBundle() localizedStringForKey:(key) value:ORKDefaultLocalizedValue(key) table:nil]
#define ORKLocalizedStringFromNumber(number) \
[NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterNoStyle]
+1
View File
@@ -155,6 +155,7 @@
// Bundle for video assets
NSBundle *ORKAssetsBundle(void);
NSBundle *ORKBundle();
NSBundle *ORKDefaultLocaleBundle();
// Pass 0xcccccc and get color #cccccc
UIColor *ORKRGB(uint32_t x);
+20 -2
View File
@@ -247,8 +247,26 @@ NSDateFormatter *ORKTimeOfDayLabelFormatter() {
}
NSBundle *ORKBundle() {
NSBundle *bundle = [NSBundle bundleForClass:[ORKStep class]];
return bundle;
static NSBundle *__bundle;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__bundle = [NSBundle bundleForClass:[ORKStep class]];
});
return __bundle;
}
NSBundle *ORKDefaultLocaleBundle() {
static NSBundle *__bundle;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *path = [ORKBundle() pathForResource:[ORKBundle() objectForInfoDictionaryKey:@"CFBundleDevelopmentRegion"] ofType:@"lproj"];
__bundle = [NSBundle bundleWithPath:path];
});
return __bundle;
}
NSDateComponentsFormatter *ORKTimeIntervalLabelFormatter() {
@@ -51,6 +51,8 @@
BOOL _isTouchIdAuthenticated;
BOOL _isPasscodeSaved;
LAContext *_touchContext;
ORKPasscodeType _authenticationPasscodeType;
BOOL _useTouchId;
}
- (ORKPasscodeStep *)passcodeStep {
@@ -78,6 +80,7 @@
_isChangingState = NO;
_isTouchIdAuthenticated = NO;
_isPasscodeSaved = NO;
_useTouchId = YES;
// Set the starting passcode state and textfield based on flow.
switch (_passcodeFlow) {
@@ -89,19 +92,19 @@
case ORKPasscodeFlowAuthenticate:
[self setValuesFromKeychain];
_passcodeStepView.textField.numberOfDigits = [self numberOfDigitsForPasscodeType:self.authenticationPasscodeType];
_passcodeStepView.textField.numberOfDigits = [self numberOfDigitsForPasscodeType:_authenticationPasscodeType];
[self changeStateTo:ORKPasscodeStateEntry];
break;
case ORKPasscodeFlowEdit:
[self setValuesFromKeychain];
_passcodeStepView.textField.numberOfDigits = [self numberOfDigitsForPasscodeType:self.authenticationPasscodeType];
_passcodeStepView.textField.numberOfDigits = [self numberOfDigitsForPasscodeType:_authenticationPasscodeType];
[self changeStateTo:ORKPasscodeStateOldEntry];
break;
}
// If Touch ID was enabled then present it for authentication flow.
if (self.useTouchId &&
if (_useTouchId &&
self.passcodeFlow == ORKPasscodeFlowAuthenticate) {
[self promptTouchId];
}
@@ -124,7 +127,9 @@
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self makePasscodeViewBecomeFirstResponder];
if (!_shouldResignFirstResponder) {
[self makePasscodeViewBecomeFirstResponder];
}
}
- (void)viewWillDisappear:(BOOL)animated {
@@ -219,13 +224,6 @@
return stepResult;
}
- (BOOL)useTouchId {
if (self.passcodeFlow == ORKPasscodeFlowCreate) {
_useTouchId = YES;
}
return _useTouchId;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@@ -253,17 +251,17 @@
}
}
- (void)makePasscodeViewBecomeFirstResponder{
if (! _passcodeStepView.textField.isFirstResponder) {
_shouldResignFirstResponder = NO;
- (void)makePasscodeViewBecomeFirstResponder {
_shouldResignFirstResponder = NO;
if (!_passcodeStepView.textField.isFirstResponder) {
[_passcodeStepView.textField becomeFirstResponder];
}
}
- (void)makePasscodeViewResignFirstResponder {
_shouldResignFirstResponder = YES;
if (_passcodeStepView.textField.isFirstResponder) {
_shouldResignFirstResponder = YES;
[_passcodeStepView.textField endEditing:YES];
[_passcodeStepView.textField resignFirstResponder];
}
}
@@ -272,7 +270,7 @@
_touchContext.localizedFallbackTitle = @"";
// Check to see if the device supports Touch ID.
if (self.useTouchId &&
if (_useTouchId &&
[_touchContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
/// Device does support Touch ID.
@@ -288,8 +286,6 @@
typeof(self) strongSelf = weakSelf;
[strongSelf makePasscodeViewBecomeFirstResponder];
if (success) {
// Store that user passed authentication.
_isTouchIdAuthenticated = YES;
@@ -305,8 +301,13 @@
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:ORKLocalizedString(@"BUTTON_OK", nil)
style:UIAlertActionStyleDefault
handler:nil]];
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf makePasscodeViewBecomeFirstResponder];
}]];
[strongSelf presentViewController:alert animated:YES completion:nil];
} else if (error.code == LAErrorUserCancel) {
[strongSelf makePasscodeViewBecomeFirstResponder];
}
[strongSelf finishTouchId];
@@ -390,8 +391,11 @@
}
NSString *storedPasscode = dictionary[KeychainDictionaryPasscodeKey];
self.useTouchId = [dictionary[KeychainDictionaryTouchIdKey] boolValue];
self.authenticationPasscodeType = (storedPasscode.length == 4) ? ORKPasscodeType4Digit : ORKPasscodeType6Digit;
_authenticationPasscodeType = (storedPasscode.length == 4) ? ORKPasscodeType4Digit : ORKPasscodeType6Digit;
if (self.passcodeFlow == ORKPasscodeFlowAuthenticate) {
_useTouchId = [dictionary[KeychainDictionaryTouchIdKey] boolValue];
}
}
- (void)wrongAttempt {
@@ -58,8 +58,6 @@ typedef NS_ENUM(NSUInteger, ORKPasscodeState) {
@property (nonatomic) ORKPasscodeFlow passcodeFlow;
@property (nonatomic, weak) id<ORKPasscodeDelegate> passcodeDelegate;
@property (nonatomic) ORKPasscodeType authenticationPasscodeType;
@property (nonatomic) BOOL useTouchId;
@end