Skip to content

Commit 8bc0e92

Browse files
authored
Merge pull request #182 from javitrujillo/master
Added support for iOS App Extensions
2 parents ad41c31 + 7c6b673 commit 8bc0e92

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 3.8.9
2+
* Added support for iOS App Extensions:
3+
* Now, if you add a macro to project settings (`LTH_APP_EXTENSIONS`), `LTHPasscodeViewController` doesn’t crash under an extension target.
4+
* Also, with a new method, you can provide a view in which the lock is going to be presented and centered in.
5+
16
# 3.8.8
27
* Fixed translations.
38

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)showLockScreenOver:(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: 23 additions & 15 deletions
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,47 +1009,51 @@ - (void)showLockscreenWithoutAnimation {
10051009
[self showLockScreenWithAnimation:NO withLogout:NO andLogoutTitle:nil];
10061010
}
10071011

1008-
10091012
- (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle {
1013+
[self showLockScreenOver:LTHMainWindow withAnimation:animated withLogout:hasLogout andLogoutTitle:logoutTitle];
1014+
}
1015+
1016+
- (void)showLockScreenOver:(UIView *)superview withAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle {
10101017
[self _prepareAsLockScreen];
10111018

10121019
// In case the user leaves the app while the lockscreen is already active.
10131020
if (_isCurrentlyOnScreen) { return; }
10141021
_isCurrentlyOnScreen = YES;
10151022

1016-
[LTHMainWindow addSubview: self.view];
1023+
[superview addSubview: self.view];
10171024

10181025
// All this hassle because a view added to UIWindow does not rotate automatically
10191026
// and if we would have added the view anywhere else, it wouldn't display properly
10201027
// (having a modal on screen when the user leaves the app, for example).
10211028
[self rotateAccordingToStatusBarOrientationAndSupportedOrientations];
1029+
CGPoint superviewCenter = CGPointMake(superview.center.x, superview.center.y);
10221030
CGPoint newCenter;
10231031
[self statusBarFrameOrOrientationChanged:nil];
10241032
if (LTHiOS8) {
10251033
self.view.center = CGPointMake(self.view.center.x, self.view.center.y * -1.f);
1026-
newCenter = CGPointMake(LTHMainWindow.center.x,
1027-
LTHMainWindow.center.y + self.navigationController.navigationBar.frame.size.height / 2);
1034+
newCenter = CGPointMake(superviewCenter.x,
1035+
superviewCenter.y + self.navigationController.navigationBar.frame.size.height / 2);
10281036
}
10291037
else {
10301038
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) {
10311039
self.view.center = CGPointMake(self.view.center.x * -1.f, self.view.center.y);
1032-
newCenter = CGPointMake(LTHMainWindow.center.x - self.navigationController.navigationBar.frame.size.height / 2,
1033-
LTHMainWindow.center.y);
1040+
newCenter = CGPointMake(superviewCenter.x - self.navigationController.navigationBar.frame.size.height / 2,
1041+
superviewCenter.y);
10341042
}
10351043
else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) {
10361044
self.view.center = CGPointMake(self.view.center.x * 2.f, self.view.center.y);
1037-
newCenter = CGPointMake(LTHMainWindow.center.x + self.navigationController.navigationBar.frame.size.height / 2,
1038-
LTHMainWindow.center.y);
1045+
newCenter = CGPointMake(superviewCenter.x + self.navigationController.navigationBar.frame.size.height / 2,
1046+
superviewCenter.y);
10391047
}
10401048
else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) {
10411049
self.view.center = CGPointMake(self.view.center.x, self.view.center.y * -1.f);
1042-
newCenter = CGPointMake(LTHMainWindow.center.x,
1043-
LTHMainWindow.center.y - self.navigationController.navigationBar.frame.size.height / 2);
1050+
newCenter = CGPointMake(superviewCenter.x,
1051+
superviewCenter.y - self.navigationController.navigationBar.frame.size.height / 2);
10441052
}
10451053
else {
10461054
self.view.center = CGPointMake(self.view.center.x, self.view.center.y * 2.f);
1047-
newCenter = CGPointMake(LTHMainWindow.center.x,
1048-
LTHMainWindow.center.y + self.navigationController.navigationBar.frame.size.height / 2);
1055+
newCenter = CGPointMake(superviewCenter.x,
1056+
superviewCenter.y + self.navigationController.navigationBar.frame.size.height / 2);
10491057
}
10501058
}
10511059

@@ -1834,12 +1842,12 @@ - (void)rotateAccordingToStatusBarOrientationAndSupportedOrientations {
18341842
CGFloat angle = UIInterfaceOrientationAngleOfOrientation(orientation);
18351843
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
18361844

1837-
[self setIfNotEqualTransform: transform
1838-
frame: self.view.window.bounds];
1845+
[self setIfNotEqualTransform: transform];
18391846
}
18401847

18411848

1842-
- (void)setIfNotEqualTransform:(CGAffineTransform)transform frame:(CGRect)frame {
1849+
- (void)setIfNotEqualTransform:(CGAffineTransform)transform {
1850+
CGRect frame = self.view.superview.frame;
18431851
if(!CGAffineTransformEqualToTransform(self.view.transform, transform)) {
18441852
self.view.transform = transform;
18451853
}

0 commit comments

Comments
 (0)