Skip to content

Commit

Permalink
Fixed a bug where the UI would not be visible
Browse files Browse the repository at this point in the history
Replaced all instances of `keyWindow` with `LTHMainWindow` (macro that expands `[UIApplication sharedApplication].windows[0]` - explanation in #164
  • Loading branch information
Roland Leth authored and Roland Leth committed Oct 26, 2016
1 parent 958b322 commit c4e8dc2
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 190 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.7.11
* Replaced all instances of `keyWindow` with `LTHMainWindow` (macro that expands `[UIApplication sharedApplication].windows[0]` - explanation in #164.
* Fixed a bug where the UI would not be visible (Closed #163).

# 3.7.10
* New delegate method: `passcodeWasEnabled`. Called when the passcode was enabled (Closed [#156](https://github.com/rolandleth/LTHPasscodeViewController/issues/156)).
* New method: `enablePasscodeWhenApplicationEntersBackground`. It reverts what `disablePasscodeWhenApplicationEntersBackground` does: it adds observers for `UIApplicationDidEnterBackgroundNotification` and `UIApplicationWillEnterForegroundNotification` (Closed [#158](https://github.com/rolandleth/LTHPasscodeViewController/issues/158)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
2AE8001B17D9503000DBDE63 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
2AE8002217D9503000DBDE63 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
2AE8003F17D9507E00DBDE63 /* LTHDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LTHDemoViewController.h; sourceTree = "<group>"; };
2AE8004017D9507E00DBDE63 /* LTHDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LTHDemoViewController.m; sourceTree = "<group>"; };
2AE8004017D9507E00DBDE63 /* LTHDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = LTHDemoViewController.m; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
2AF06FCC1A19F89E00C6F836 /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-PT"; path = "pt-PT.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
2AF1958E182C09D5005CE38A /* LTHPasscodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = LTHPasscodeViewController.h; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
2AF1958F182C09D5005CE38A /* LTHPasscodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = LTHPasscodeViewController.m; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
Expand Down
248 changes: 133 additions & 115 deletions Demo/LTHPasscodeViewController Demo/LTHDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,181 +28,199 @@ @implementation LTHDemoViewController


- (void)_refreshUI {
if ([LTHPasscodeViewController doesPasscodeExist]) {
_enablePasscode.enabled = NO;
_changePasscode.enabled = YES;
_turnOffPasscode.enabled = YES;
_testPasscode.enabled = YES;
_changePasscode.backgroundColor = [UIColor colorWithRed:0.50f green:0.30f blue:0.87f alpha:1.00f];
_testPasscode.backgroundColor = [UIColor colorWithRed:0.000f green:0.645f blue:0.608f alpha:1.000f];
_enablePasscode.backgroundColor = [UIColor colorWithWhite: 0.8f alpha: 1.0f];
_turnOffPasscode.backgroundColor = [UIColor colorWithRed:0.8f green:0.1f blue:0.2f alpha:1.000f];
}
else {
_enablePasscode.enabled = YES;
_changePasscode.enabled = NO;
_turnOffPasscode.enabled = NO;
_testPasscode.enabled = NO;
_changePasscode.backgroundColor = [UIColor colorWithWhite: 0.8f alpha: 1.0f];
_enablePasscode.backgroundColor = [UIColor colorWithRed:0.000f green:0.645f blue:0.608f alpha:1.000f];
_testPasscode.backgroundColor = [UIColor colorWithWhite: 0.8f alpha: 1.0f];
_turnOffPasscode.backgroundColor = [UIColor colorWithWhite: 0.8f alpha: 1.0f];
}
_typeSwitch.on = [[LTHPasscodeViewController sharedUser] isSimple];
_touchIDSwitch.on = [[LTHPasscodeViewController sharedUser] allowUnlockWithTouchID];
if ([LTHPasscodeViewController doesPasscodeExist]) {
_enablePasscode.enabled = NO;
_changePasscode.enabled = YES;
_turnOffPasscode.enabled = YES;
_testPasscode.enabled = YES;
_changePasscode.backgroundColor = [UIColor colorWithRed:0.50f green:0.30f blue:0.87f alpha:1.00f];
_testPasscode.backgroundColor = [UIColor colorWithRed:0.000f green:0.645f blue:0.608f alpha:1.000f];
_enablePasscode.backgroundColor = [UIColor colorWithWhite: 0.8f alpha: 1.0f];
_turnOffPasscode.backgroundColor = [UIColor colorWithRed:0.8f green:0.1f blue:0.2f alpha:1.000f];
}
else {
_enablePasscode.enabled = YES;
_changePasscode.enabled = NO;
_turnOffPasscode.enabled = NO;
_testPasscode.enabled = NO;
_changePasscode.backgroundColor = [UIColor colorWithWhite: 0.8f alpha: 1.0f];
_enablePasscode.backgroundColor = [UIColor colorWithRed:0.000f green:0.645f blue:0.608f alpha:1.000f];
_testPasscode.backgroundColor = [UIColor colorWithWhite: 0.8f alpha: 1.0f];
_turnOffPasscode.backgroundColor = [UIColor colorWithWhite: 0.8f alpha: 1.0f];
}
_typeSwitch.on = [[LTHPasscodeViewController sharedUser] isSimple];
_touchIDSwitch.on = [[LTHPasscodeViewController sharedUser] allowUnlockWithTouchID];
}

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Demo";
self.view.backgroundColor = [UIColor whiteColor];
[LTHPasscodeViewController sharedUser].delegate = self;
[LTHPasscodeViewController sharedUser].maxNumberOfAllowedFailedAttempts = 3;
_changePasscode = [UIButton buttonWithType: UIButtonTypeCustom];
_enablePasscode = [UIButton buttonWithType: UIButtonTypeCustom];
_testPasscode = [UIButton buttonWithType: UIButtonTypeCustom];
_turnOffPasscode = [UIButton buttonWithType: UIButtonTypeCustom];
_enablePasscode.frame = CGRectMake(100, 100, 100, 50);
_testPasscode.frame = CGRectMake(100, 200, 100, 50);
_changePasscode.frame = CGRectMake(100, 300, 100, 50);
_turnOffPasscode.frame = CGRectMake(100, 400, 100, 50);
if ([self isTouchIDAvailable]) {
_typeLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 190, 60, 30}];
_typeSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 220, 100, 100}];
_touchIDLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 290, 90, 30}];
_touchIDSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 320, 100, 100}];
_touchIDLabel.text = @"Touch ID";
[_touchIDSwitch addTarget:self action:@selector(_touchIDPasscodeType:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_touchIDSwitch];
[self.view addSubview:_touchIDLabel];
} else {
_typeLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 230, 60, 30}];
_typeSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 260, 100, 100}];
}
[_turnOffPasscode setTitle: @"Turn Off" forState: UIControlStateNormal];
[_changePasscode setTitle: @"Change" forState: UIControlStateNormal];
[_testPasscode setTitle: @"Test" forState: UIControlStateNormal];
[_enablePasscode setTitle: @"Enable" forState: UIControlStateNormal];
_typeLabel.text = @"Simple";
[self _refreshUI];
[_changePasscode addTarget: self action: @selector(_changePasscode) forControlEvents: UIControlEventTouchUpInside];
[_enablePasscode addTarget: self action: @selector(_enablePasscode) forControlEvents: UIControlEventTouchUpInside];
[_testPasscode addTarget: self action: @selector(_testPasscode) forControlEvents: UIControlEventTouchUpInside];
[_turnOffPasscode addTarget: self action: @selector(_turnOffPasscode) forControlEvents: UIControlEventTouchUpInside];
[_typeSwitch addTarget:self action:@selector(_switchPasscodeType:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview: _changePasscode];
[self.view addSubview: _turnOffPasscode];
[self.view addSubview: _testPasscode];
[self.view addSubview: _enablePasscode];
[self.view addSubview:_typeSwitch];
[self.view addSubview:_typeLabel];
[super viewDidLoad];
self.title = @"Demo";
self.view.backgroundColor = [UIColor whiteColor];
[LTHPasscodeViewController sharedUser].delegate = self;
[LTHPasscodeViewController sharedUser].maxNumberOfAllowedFailedAttempts = 3;
_changePasscode = [UIButton buttonWithType: UIButtonTypeCustom];
_enablePasscode = [UIButton buttonWithType: UIButtonTypeCustom];
_testPasscode = [UIButton buttonWithType: UIButtonTypeCustom];
_turnOffPasscode = [UIButton buttonWithType: UIButtonTypeCustom];
_enablePasscode.frame = CGRectMake(100, 100, 100, 50);
_testPasscode.frame = CGRectMake(100, 200, 100, 50);
_changePasscode.frame = CGRectMake(100, 300, 100, 50);
_turnOffPasscode.frame = CGRectMake(100, 400, 100, 50);
if ([self isTouchIDAvailable]) {
_typeLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 190, 60, 30}];
_typeSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 220, 100, 100}];
_touchIDLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 290, 90, 30}];
_touchIDSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 320, 100, 100}];
_touchIDLabel.text = @"Touch ID";
[_touchIDSwitch addTarget:self action:@selector(_touchIDPasscodeType:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_touchIDSwitch];
[self.view addSubview:_touchIDLabel];
} else {
_typeLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 230, 60, 30}];
_typeSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 260, 100, 100}];
}
[_turnOffPasscode setTitle: @"Turn Off" forState: UIControlStateNormal];
[_changePasscode setTitle: @"Change" forState: UIControlStateNormal];
[_testPasscode setTitle: @"Test" forState: UIControlStateNormal];
[_enablePasscode setTitle: @"Enable" forState: UIControlStateNormal];
_typeLabel.text = @"Simple";
[self _refreshUI];
[_changePasscode addTarget: self action: @selector(_changePasscode) forControlEvents: UIControlEventTouchUpInside];
[_enablePasscode addTarget: self action: @selector(_enablePasscode) forControlEvents: UIControlEventTouchUpInside];
[_testPasscode addTarget: self action: @selector(_testPasscode) forControlEvents: UIControlEventTouchUpInside];
[_turnOffPasscode addTarget: self action: @selector(_turnOffPasscode) forControlEvents: UIControlEventTouchUpInside];
[_typeSwitch addTarget:self action:@selector(_switchPasscodeType:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview: _changePasscode];
[self.view addSubview: _turnOffPasscode];
[self.view addSubview: _testPasscode];
[self.view addSubview: _enablePasscode];
[self.view addSubview:_typeSwitch];
[self.view addSubview:_typeLabel];
}


- (void)_turnOffPasscode {
[self showLockViewForTurningPasscodeOff];
[self showLockViewForTurningPasscodeOff];
}


- (void)_changePasscode {
[self showLockViewForChangingPasscode];
[self showLockViewForChangingPasscode];
}


- (void)_enablePasscode {
[self showLockViewForEnablingPasscode];
[self showLockViewForEnablingPasscode];
}


- (void)_testPasscode {
[self showLockViewForTestingPasscode];
// MARK: Please read
// Please check Issue #16 on the GitHub repo, or this Stack Overflow question, maybe you can give a hand:
// http://stackoverflow.com/questions/19816142/uialertviews-uiactionsheets-and-keywindow-problems
// https://github.com/rolandleth/LTHPasscodeViewController/issues/16
// The issue started with a positioning problem, which is now fixed, but it revealed another kinda hard to fix problem.
// UIActionSheet *as = [[UIActionSheet alloc] initWithTitle: @"aa" delegate: nil cancelButtonTitle: @"aa" destructiveButtonTitle:@"ss" otherButtonTitles: nil];
// [as showInView: self.view];
// UIAlertView *av = [[UIAlertView alloc] initWithTitle: @"aa" message: @"ss" delegate: nil cancelButtonTitle: @"c" otherButtonTitles: nil];
// [av show];
// MARK: Please read
/*
The issue (#16) started with a positioning problem, which is now fixed, but it revealed another kinda hard to fix problem - displaying the lockscreen when an alertView / actionSheet is visible, or displaying one after the lockscreen is visible results in a few cases:
* the lockscreen and the keyboard appear on top the av/as, but
* the dimming of the av/as appears on top the lockscreen;
* if the app is closed and reopened, the order becomes av/as - lockscreen - dimming - keyboard.
* the lockscreen always appears behind the av/as, while the keyboard (windows[0])
* doesn't appear until the av/as is dismissed;
* appears on top on the av/as - if the app is closed and reopened with the av/as visible.
* the lockscreen appears above the av/as, while the keyboard appears below, so there's no way to enter the passcode. (keyWindow)
The current implementation shows the lockscreen behind the av/as.
Relevant links:
* https://github.com/rolandleth/LTHPasscodeViewController/issues/16
* https://github.com/rolandleth/LTHPasscodeViewController/issues/164 (the description found above)
* https://stackoverflow.com/questions/19816142/uialertviews-uiactionsheets-and-keywindow-problems
Any help would be greatly appreciated.
*/

// UIActionSheet *as = [[UIActionSheet alloc] initWithTitle: @"aa" delegate: nil cancelButtonTitle: @"aa" destructiveButtonTitle:@"ss" otherButtonTitles: nil];
// [as showInView: self.view];

[self showLockViewForTestingPasscode];

// UIAlertView *av = [[UIAlertView alloc] initWithTitle: @"aa" message: @"ss" delegate: nil cancelButtonTitle: @"c" otherButtonTitles: nil];
// [av show];
}

- (void)_switchPasscodeType:(UISwitch *)sender {
[[LTHPasscodeViewController sharedUser] setIsSimple:sender.isOn
inViewController:self
asModal:YES];
[[LTHPasscodeViewController sharedUser] setIsSimple:sender.isOn
inViewController:self
asModal:YES];
}

- (void)_touchIDPasscodeType:(UISwitch *)sender {
[[LTHPasscodeViewController sharedUser] setAllowUnlockWithTouchID:sender.isOn];
[[LTHPasscodeViewController sharedUser] setAllowUnlockWithTouchID:sender.isOn];
}

- (void)showLockViewForEnablingPasscode {
[[LTHPasscodeViewController sharedUser] showForEnablingPasscodeInViewController:self
asModal:YES];
[[LTHPasscodeViewController sharedUser] showForEnablingPasscodeInViewController:self
asModal:YES];
}


- (void)showLockViewForTestingPasscode {
[[LTHPasscodeViewController sharedUser] showLockScreenWithAnimation:YES
withLogout:NO
andLogoutTitle:nil];
[[LTHPasscodeViewController sharedUser] showLockScreenWithAnimation:YES
withLogout:NO
andLogoutTitle:nil];
}


- (void)showLockViewForChangingPasscode {
[LTHPasscodeViewController sharedUser].hidesCancelButton = NO;
[LTHPasscodeViewController sharedUser].hidesBackButton = NO;
[[LTHPasscodeViewController sharedUser] showForChangingPasscodeInViewController:self asModal:NO];
[LTHPasscodeViewController sharedUser].hidesCancelButton = NO;
[LTHPasscodeViewController sharedUser].hidesBackButton = NO;
[[LTHPasscodeViewController sharedUser] showForChangingPasscodeInViewController:self asModal:NO];
}


- (void)showLockViewForTurningPasscodeOff {
[[LTHPasscodeViewController sharedUser] showForDisablingPasscodeInViewController:self
asModal:NO];
[[LTHPasscodeViewController sharedUser] showForDisablingPasscodeInViewController:self
asModal:NO];
}

- (BOOL)isTouchIDAvailable {
if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending) {
return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
}
return NO;
if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending) {
return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
}
return NO;
}

# pragma mark - LTHPasscodeViewController Delegates -

- (void)passcodeViewControllerWillClose {
NSLog(@"Passcode View Controller Will Be Closed");
[self _refreshUI];
NSLog(@"Passcode View Controller Will Be Closed");
[self _refreshUI];
}

- (void)maxNumberOfFailedAttemptsReached {
[LTHPasscodeViewController deletePasscodeAndClose];
NSLog(@"Max Number of Failed Attemps Reached");
[LTHPasscodeViewController deletePasscodeAndClose];
NSLog(@"Max Number of Failed Attemps Reached");
}

- (void)passcodeWasEnteredSuccessfully {
NSLog(@"Passcode Was Entered Successfully");
NSLog(@"Passcode Was Entered Successfully");
}

- (void)logoutButtonWasPressed {
NSLog(@"Logout Button Was Pressed");
NSLog(@"Logout Button Was Pressed");
}

- (void)passcodeWasEnabled {
NSLog(@"Passcode Was Enabled");
NSLog(@"Passcode Was Enabled");
}


Expand Down
Loading

0 comments on commit c4e8dc2

Please sign in to comment.