Skip to content

Commit 792fa72

Browse files
committed
Added support for iOS App Extensions
Now, if you add a macro to project settings, LTHPasscode doesn’t crash. Also, with a new method, you can provide the size of the view in which the LHTPasscode view is going to be presented.
1 parent 0b49a9a commit 792fa72

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

LTHPasscodeViewController/LTHPasscodeViewController.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@
313313
@param logoutTitle The title of the Logout button.
314314
*/
315315
- (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle;
316+
/**
317+
@brief Used for displaying the lock. The passcode view is added directly on the keyWindow.
318+
@param superview The superview where is to be presented, used to measure the center of the view.
319+
@param hasLogout Set to @c YES for a navBar with a Logout button, set to @c NO for no navBar.
320+
@param logoutTitle The title of the Logout button.
321+
*/
322+
- (void)showLockScreenIntoSuperview:(UIView *)superview WithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle;
316323
/**
317324
@brief Used for enabling the passcode.
318325
@details The back bar button is hidden by default. Set @c hidesBackButton to @c NO if you want it to be visible.

LTHPasscodeViewController/LTHPasscodeViewController.m

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949
Any help would be greatly appreciated.
5050
*/
5151

52+
#if defined(LTH_APP_EXTENSIONS)
53+
#define LTHMainWindow [UIApplication sharedApplication].keyWindow
54+
#else
5255
#define LTHMainWindow [UIApplication sharedApplication].windows[0]
56+
#endif
5357

5458
@interface LTHPasscodeViewController () <UITextFieldDelegate>
5559
@property (nonatomic, strong) UIView *coverView;
@@ -1005,7 +1009,6 @@ - (void)showLockscreenWithoutAnimation {
10051009
[self showLockScreenWithAnimation:NO withLogout:NO andLogoutTitle:nil];
10061010
}
10071011

1008-
10091012
- (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle {
10101013
[self _prepareAsLockScreen];
10111014

@@ -1048,7 +1051,60 @@ - (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout an
10481051
LTHMainWindow.center.y + self.navigationController.navigationBar.frame.size.height / 2);
10491052
}
10501053
}
1054+
[UIView animateWithDuration: animated ? _lockAnimationDuration : 0 animations: ^{
1055+
self.view.center = newCenter;
1056+
}];
1057+
1058+
// Add nav bar & logout button if specified
1059+
if (hasLogout) {
1060+
_isUsingNavBar = hasLogout;
1061+
[self _setupNavBarWithLogoutTitle:logoutTitle];
1062+
}
1063+
}
1064+
1065+
- (void)showLockScreenIntoSuperview:(UIView *)superview WithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle {
1066+
[self _prepareAsLockScreen];
10511067

1068+
// In case the user leaves the app while the lockscreen is already active.
1069+
if (_isCurrentlyOnScreen) { return; }
1070+
_isCurrentlyOnScreen = YES;
1071+
1072+
[superview addSubview: self.view];
1073+
1074+
// All this hassle because a view added to UIWindow does not rotate automatically
1075+
// and if we would have added the view anywhere else, it wouldn't display properly
1076+
// (having a modal on screen when the user leaves the app, for example).
1077+
[self rotateAccordingToStatusBarOrientationAndSupportedOrientations];
1078+
CGPoint superviewCenter = CGPointMake(superview.frame.size.width/2, superview.frame.size.height/2);
1079+
CGPoint newCenter;
1080+
[self statusBarFrameOrOrientationChanged:nil];
1081+
if (LTHiOS8) {
1082+
self.view.center = CGPointMake(self.view.center.x, self.view.center.y * -1.f);
1083+
newCenter = CGPointMake(superviewCenter.x,
1084+
superviewCenter.y + self.navigationController.navigationBar.frame.size.height / 2);
1085+
}
1086+
else {
1087+
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) {
1088+
self.view.center = CGPointMake(self.view.center.x * -1.f, self.view.center.y);
1089+
newCenter = CGPointMake(superviewCenter.x - self.navigationController.navigationBar.frame.size.height / 2,
1090+
superviewCenter.y);
1091+
}
1092+
else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) {
1093+
self.view.center = CGPointMake(self.view.center.x * 2.f, self.view.center.y);
1094+
newCenter = CGPointMake(superviewCenter.x + self.navigationController.navigationBar.frame.size.height / 2,
1095+
superviewCenter.y);
1096+
}
1097+
else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) {
1098+
self.view.center = CGPointMake(self.view.center.x, self.view.center.y * -1.f);
1099+
newCenter = CGPointMake(superviewCenter.x,
1100+
superviewCenter.y - self.navigationController.navigationBar.frame.size.height / 2);
1101+
}
1102+
else {
1103+
self.view.center = CGPointMake(self.view.center.x, self.view.center.y * 2.f);
1104+
newCenter = CGPointMake(superviewCenter.x,
1105+
superviewCenter.y + self.navigationController.navigationBar.frame.size.height / 2);
1106+
}
1107+
}
10521108
[UIView animateWithDuration: animated ? _lockAnimationDuration : 0 animations: ^{
10531109
self.view.center = newCenter;
10541110
}];

0 commit comments

Comments
 (0)