-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lock completion enums, refactor lock to use touchID #59
Open
dasmer
wants to merge
4
commits into
daz/2.0
Choose a base branch
from
daz/touchLock_completion
base: daz/2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,86 +192,52 @@ - (void)lock | |
return; | ||
} | ||
|
||
__weak typeof(self) weakSelf = self; | ||
BOOL fromBackground = [UIApplication sharedApplication].applicationState == UIApplicationStateBackground; | ||
UIViewController *displayViewController; | ||
UIView *snapshotView; | ||
void (^displayPresentationCompletionBlock)(); | ||
BOOL shouldUseSplash = ((self.splashViewControllerClass != NULL) | ||
&& ([self.splashViewControllerClass isSubclassOfClass:[VENTouchLockSplashViewController class]])); | ||
|
||
if (self.splashViewControllerClass != NULL) { | ||
VENTouchLockSplashViewController *splashViewController = [[self.splashViewControllerClass alloc] init]; | ||
if (shouldUseSplash) { | ||
VENTouchLockSplashViewController *splashViewController = [self splashViewController]; | ||
|
||
void (^didFinishWithResult)(BOOL success, VENTouchLockSplashViewControllerUnlockType unlockType) = splashViewController.didFinishWithResult; | ||
BOOL shouldEmbedInNavigationController = self.options.splashShouldEmbedInNavigationController; | ||
UIViewController *displayViewController; | ||
displayViewController = [self transformViewController:splashViewController byEmbedding:shouldEmbedInNavigationController]; | ||
|
||
splashViewController.didFinishWithResult = ^(BOOL success, VENTouchLockSplashViewControllerUnlockType unlockType) { | ||
__strong typeof(self) strongSelf = weakSelf; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
strongSelf.locked = NO; | ||
if (didFinishWithResult) { | ||
didFinishWithResult(success, unlockType); | ||
} | ||
}); | ||
}; | ||
self.locked = YES; | ||
|
||
displayPresentationCompletionBlock = ^{ | ||
[splashViewController showUnlockAnimated:NO]; | ||
}; | ||
if (fromBackground) { | ||
VENTouchLockSplashViewController *snapshotSplashViewController = [[self.splashViewControllerClass alloc] init]; | ||
UIViewController *snapshotDisplayController = [self transformViewController:snapshotSplashViewController byEmbedding:shouldEmbedInNavigationController]; | ||
[snapshotDisplayController loadView]; | ||
[snapshotDisplayController viewDidLoad]; | ||
[self showSnapshotView:snapshotSplashViewController.view]; | ||
} | ||
|
||
if ([splashViewController isKindOfClass:[VENTouchLockSplashViewController class]]) { | ||
if (self.options.splashShouldEmbedInNavigationController) { | ||
displayViewController = [splashViewController ventouchlock_embeddedInNavigationControllerWithNavigationBarClass:self.options.navigationBarClass]; | ||
} | ||
else { | ||
displayViewController = splashViewController; | ||
} | ||
[self presentViewControllerOnTop:displayViewController completion:^{ | ||
[splashViewController showUnlockAnimated:NO]; | ||
}]; | ||
|
||
if (fromBackground) { | ||
VENTouchLockSplashViewController *snapshotSplashViewController = [[self.splashViewControllerClass alloc] init]; | ||
UIViewController *snapshotDisplayController; | ||
if (self.options.splashShouldEmbedInNavigationController) { | ||
snapshotDisplayController = [snapshotSplashViewController ventouchlock_embeddedInNavigationControllerWithNavigationBarClass:self.options.navigationBarClass]; | ||
} | ||
else { | ||
snapshotDisplayController = snapshotSplashViewController; | ||
} | ||
[snapshotDisplayController loadView]; | ||
[snapshotDisplayController viewDidLoad]; | ||
snapshotView = snapshotDisplayController.view; | ||
} | ||
} | ||
} else { | ||
VENTouchLockEnterPasscodeViewController *enterPasscodeViewController = [[VENTouchLockEnterPasscodeViewController alloc] initWithTouchLock:self]; | ||
enterPasscodeViewController.didFinishWithResult = ^(BOOL success) { | ||
__strong typeof(self) strongSelf = weakSelf; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
strongSelf.locked = NO; | ||
}); | ||
}; | ||
if (self.options.passcodeViewControllerShouldEmbedInNavigationController) { | ||
displayViewController = [enterPasscodeViewController ventouchlock_embeddedInNavigationControllerWithNavigationBarClass:self.options.navigationBarClass]; | ||
} else { | ||
displayViewController = enterPasscodeViewController; | ||
if (self.shouldUseTouchID) { | ||
[self showTouchID]; | ||
} | ||
else { | ||
VENTouchLockEnterPasscodeViewController *enterPasscodeViewController = [self enterPasscodeViewController]; | ||
|
||
if (fromBackground && self.appSwitchViewClass != NULL) { | ||
snapshotView = [[self.appSwitchViewClass alloc] initWithFrame:CGRectZero]; | ||
} | ||
} | ||
BOOL shouldEmbedInNavigationController = self.options.passcodeViewControllerShouldEmbedInNavigationController; | ||
|
||
self.locked = YES; | ||
UIViewController *displayViewController = [self transformViewController:enterPasscodeViewController | ||
byEmbedding:shouldEmbedInNavigationController]; | ||
|
||
if (fromBackground && snapshotView) { | ||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; | ||
UIWindow *mainWindow = [[UIApplication sharedApplication].windows firstObject]; | ||
snapshotView.frame = mainWindow.bounds; | ||
[mainWindow addSubview:snapshotView]; | ||
self.snapshotView = snapshotView; | ||
} | ||
self.locked = YES; | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
UIViewController *rootViewController = [UIViewController ventouchlock_topMostController]; | ||
[rootViewController presentViewController:displayViewController animated:NO completion:displayPresentationCompletionBlock]; | ||
}); | ||
if (fromBackground && self.appSwitchViewClass != NULL) { | ||
UIView *snapshotView = [[self.appSwitchViewClass alloc] init]; | ||
[self showSnapshotView:snapshotView]; | ||
} | ||
[self presentViewControllerOnTop:displayViewController completion:nil]; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
@@ -329,19 +295,6 @@ - (void)applicationWillEnterForeground:(NSNotification *)notification | |
} | ||
|
||
|
||
#pragma mark - Internal | ||
|
||
- (NSString *)keychainPasscodeAttemptAccountName | ||
{ | ||
return [self.keychainPasscodeAccount stringByAppendingString:@"_AttemptName"]; | ||
} | ||
|
||
- (NSString *)keypathOfAutolockOptions | ||
{ | ||
return [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(options)), NSStringFromSelector(@selector(shouldAutoLockOnAppLifeCycleNotifications))]; | ||
} | ||
|
||
|
||
#pragma mark - NSObject | ||
|
||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context | ||
|
@@ -373,8 +326,146 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N | |
self.obscureView = nil; | ||
}]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
#pragma mark - Internal Helper Methods | ||
|
||
- (void)showTouchID | ||
{ | ||
[self requestTouchIDWithCompletion:^(VENTouchLockTouchIDResponse response) { | ||
switch (response) { | ||
case VENTouchLockTouchIDResponseSuccess: { | ||
self.locked = NO; | ||
if (self.lockCompletion) { | ||
self.lockCompletion(VENTouchLockCompletionPasscodeUnlock); | ||
} | ||
break; | ||
} | ||
case VENTouchLockTouchIDResponseCanceled: { | ||
self.locked = NO; | ||
if (self.lockCompletion) { | ||
self.lockCompletion(VENTouchLockCompletionCancel); | ||
} | ||
break; | ||
} | ||
case VENTouchLockTouchIDResponseUsePasscode: { | ||
VENTouchLockEnterPasscodeViewController *enterPasscodeViewController = [self enterPasscodeViewController]; | ||
BOOL shouldEmbedInNavigationController = self.options.passcodeViewControllerShouldEmbedInNavigationController; | ||
|
||
UIViewController *displayViewController = [self transformViewController:enterPasscodeViewController | ||
byEmbedding:shouldEmbedInNavigationController]; | ||
[self presentViewControllerOnTop:displayViewController completion:nil]; | ||
break; | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
}]; | ||
} | ||
|
||
- (void)showSnapshotView:(UIView *)snapshotView | ||
{ | ||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; | ||
UIWindow *mainWindow = [[UIApplication sharedApplication].windows firstObject]; | ||
snapshotView.frame = mainWindow.bounds; | ||
[mainWindow addSubview:snapshotView]; | ||
self.snapshotView = snapshotView; | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline |
||
- (void)presentViewControllerOnTop:(UIViewController *)viewController completion:(void (^)())completion | ||
{ | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
UIViewController *rootViewController = [UIViewController ventouchlock_topMostController]; | ||
[rootViewController presentViewController:viewController animated:NO completion:completion]; | ||
}); | ||
} | ||
|
||
- (NSString *)keychainPasscodeAttemptAccountName | ||
{ | ||
return [self.keychainPasscodeAccount stringByAppendingString:@"_AttemptName"]; | ||
} | ||
|
||
- (NSString *)keypathOfAutolockOptions | ||
{ | ||
return [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(options)), NSStringFromSelector(@selector(shouldAutoLockOnAppLifeCycleNotifications))]; | ||
} | ||
|
||
- (VENTouchLockSplashViewController *)splashViewController | ||
{ | ||
VENTouchLockSplashViewController *splashViewController = [[self.splashViewControllerClass alloc] init]; | ||
|
||
void (^didFinishWithResult)(BOOL success, VENTouchLockSplashViewControllerUnlockType unlockType) = splashViewController.didFinishWithResult; | ||
|
||
__weak typeof(self) weakSelf = self; | ||
splashViewController.didFinishWithResult = ^(BOOL success, VENTouchLockSplashViewControllerUnlockType unlockType) { | ||
__strong typeof(self) strongSelf = weakSelf; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
strongSelf.locked = NO; | ||
if (didFinishWithResult) { | ||
didFinishWithResult(success, unlockType); | ||
} | ||
|
||
VENTouchLockCompletion lockCompletion; | ||
if (success) { | ||
switch (unlockType) { | ||
case VENTouchLockSplashViewControllerUnlockTypeTouchID: { | ||
lockCompletion = VENTouchLockCompletionFingerprintUnlock; | ||
break; | ||
} | ||
case VENTouchLockSplashViewControllerUnlockTypePasscode: { | ||
lockCompletion = VENTouchLockCompletionPasscodeUnlock; | ||
break; | ||
} | ||
default: { | ||
lockCompletion = VENTouchLockCompletionUndefined; | ||
break; | ||
} | ||
} | ||
} else { | ||
lockCompletion = VENTouchLockCompletionPasscodeLimitReached; | ||
} | ||
if (strongSelf.lockCompletion) { | ||
self.lockCompletion(lockCompletion); | ||
} | ||
}); | ||
}; | ||
|
||
return splashViewController; | ||
} | ||
|
||
- (VENTouchLockEnterPasscodeViewController *)enterPasscodeViewController | ||
{ | ||
VENTouchLockEnterPasscodeViewController *enterPasscodeViewController = [[VENTouchLockEnterPasscodeViewController alloc] initWithTouchLock:self]; | ||
|
||
__weak typeof(self) weakSelf = self; | ||
enterPasscodeViewController.didFinishWithResult = ^(BOOL success) { | ||
__strong typeof(self) strongSelf = weakSelf; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
strongSelf.locked = NO; | ||
VENTouchLockCompletion lockCompletion = success ? VENTouchLockCompletionPasscodeUnlock : VENTouchLockCompletionCancel; | ||
if (strongSelf.lockCompletion) { | ||
self.lockCompletion(lockCompletion); | ||
} | ||
}); | ||
}; | ||
return enterPasscodeViewController; | ||
} | ||
|
||
- (UIViewController *)transformViewController:(UIViewController *)vc byEmbedding:(BOOL)shouldEmbed | ||
{ | ||
UIViewController *viewController; | ||
if (shouldEmbed) { | ||
viewController = [vc ventouchlock_embeddedInNavigationControllerWithNavigationBarClass:self.options.navigationBarClass]; | ||
} | ||
else { | ||
viewController = vc; | ||
} | ||
return viewController; | ||
} | ||
|
||
@end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to
VENTouchLockCompletionTouchIDUnlock