Permalink
Browse files

Fixes some issues with the passcode lock

- Now works properly on iPad (including rotation)
- Covers the whole screen on iPad
- Passcode lock is shown immediately when the app resigns active status,
  so that the previous screen doesn't flash briefly before the lock appears
- Passcode lock now works when another modal view controller is already
  visible (like settings or "About")
- Adjusted the coding style to the rest of the project (spaces are now tabs)
- It is no longer possible to irreversibly dismiss the keyboard on iPad
  (Tapping the main passcode view brings it up again if it was dismissed)
  • Loading branch information...
1 parent 9154c11 commit fd918a94fb2c76501b7315d9091b8cdbfdeb7068 Ole Zorn committed Jan 23, 2012
@@ -1403,6 +1403,7 @@
7FDF601D13DD2125005F1E2D /* Dashboard */,
7FDF602013DD21D5005F1E2D /* Common UI */,
7F7F1D0413F63F7F00F18143 /* Promo Code Download */,
+ 7F88897A14CD4C9A007604D7 /* Passcode Lock */,
7F1499D113BE312100D89064 /* Report Download */,
7F89BCDA13DFA43E001C607F /* Review Download */,
7F709D9013BD06570008DBAD /* Model */,
@@ -1643,6 +1644,21 @@
name = Payments;
sourceTree = "<group>";
};
+ 7F88897A14CD4C9A007604D7 /* Passcode Lock */ = {
+ isa = PBXGroup;
+ children = (
+ 6D81574814CB3C2B005E8F3F /* KKKeychain.h */,
+ 6D81574914CB3C2B005E8F3F /* KKKeychain.m */,
+ 6D81574A14CB3C2B005E8F3F /* KKPasscodeLock.h */,
+ 6D81574B14CB3C2B005E8F3F /* KKPasscodeLock.m */,
+ 6D81574C14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.h */,
+ 6D81574D14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.m */,
+ 6D81574E14CB3C2B005E8F3F /* KKPasscodeViewController.h */,
+ 6D81574F14CB3C2B005E8F3F /* KKPasscodeViewController.m */,
+ );
+ name = "Passcode Lock";
+ sourceTree = "<group>";
+ };
7F89BCDA13DFA43E001C607F /* Review Download */ = {
isa = PBXGroup;
children = (
@@ -1677,14 +1693,6 @@
7FDF601C13DD2107005F1E2D /* Helpers */ = {
isa = PBXGroup;
children = (
- 6D81574814CB3C2B005E8F3F /* KKKeychain.h */,
- 6D81574914CB3C2B005E8F3F /* KKKeychain.m */,
- 6D81574A14CB3C2B005E8F3F /* KKPasscodeLock.h */,
- 6D81574B14CB3C2B005E8F3F /* KKPasscodeLock.m */,
- 6D81574C14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.h */,
- 6D81574D14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.m */,
- 6D81574E14CB3C2B005E8F3F /* KKPasscodeViewController.h */,
- 6D81574F14CB3C2B005E8F3F /* KKPasscodeViewController.m */,
7F7F4A0313E4F4AD006C6651 /* JSONKit.h */,
7F7F4A0413E4F4AD006C6651 /* JSONKit.m */,
7F454F9E13D5C24F00AE47D1 /* UIColor+Extensions.h */,
@@ -38,5 +38,6 @@
- (NSURL *)applicationSupportDirectory;
- (void)loadAccount:(ASAccount *)account;
- (void)selectAccount:(id)sender;
+- (void)showPasscodeLockIfNeeded;
@end
@@ -26,9 +26,9 @@ @implementation AppSalesAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- [[KKPasscodeLock sharedLock] setDefaultSettings];
- [[KKPasscodeLock sharedLock] setEraseOption:NO];
-
+ [[KKPasscodeLock sharedLock] setDefaultSettings];
+ [[KKPasscodeLock sharedLock] setEraseOption:NO];
+
srandom(time(NULL));
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
@@ -49,7 +49,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
- } else {
+ } else {
self.accountsViewController = [[[AccountsViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
self.accountsViewController.managedObjectContext = self.managedObjectContext;
self.accountsViewController.contentSizeForViewInPopover = CGSizeMake(320, 480);
@@ -59,7 +59,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.accountsPopover = [[[UIPopoverController alloc] initWithContentViewController:accountsNavController] autorelease];
[self loadAccount:nil];
[self.window makeKeyAndVisible];
- [self selectAccount:nil];
}
BOOL migrating = [self migrateDataIfNeeded];
@@ -81,12 +80,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self.accountsViewController performSelector:@selector(downloadReports:) withObject:nil afterDelay:0.0];
}
+ [self showPasscodeLockIfNeeded];
+ if (iPad) {
+ [self selectAccount:nil];
+ }
+
return YES;
}
- (void)selectAccount:(id)sender
{
- [self.accountsPopover presentPopoverFromRect:CGRectMake(50, 50, 1, 1) inView:self.window.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
+ if (!self.window.rootViewController.modalViewController) {
+ [self.accountsPopover presentPopoverFromRect:CGRectMake(50, 50, 1, 1) inView:self.window.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
+ }
}
- (void)accountsViewController:(AccountsViewController *)viewController didSelectAccount:(ASAccount *)account
@@ -135,7 +141,7 @@ - (void)loadAccount:(ASAccount *)account
UITabBarController *tabController = [[[UITabBarController alloc] initWithNibName:nil bundle:nil] autorelease];
[tabController setViewControllers:[NSArray arrayWithObjects:salesNavController, reviewsNavController, paymentsNavController, promoNavController, nil]];
- self.window.rootViewController = tabController;
+ self.window.rootViewController = tabController;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
@@ -208,30 +214,50 @@ - (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
-
- if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
- KKPasscodeViewController *vc = [[[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil] autorelease];
- vc.mode = KKPasscodeModeEnter;
- vc.delegate = self;
-
- dispatch_async(dispatch_get_main_queue(),^ {
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- nav.modalPresentationStyle = UIModalPresentationFormSheet;
- nav.navigationBar.barStyle = UIBarStyleBlack;
- nav.navigationBar.opaque = NO;
- } else {
- nav.navigationBar.tintColor = accountsViewController.navigationController.navigationBar.tintColor;
- nav.navigationBar.translucent = accountsViewController.navigationController.navigationBar.translucent;
- nav.navigationBar.opaque = accountsViewController.navigationController.navigationBar.opaque;
- nav.navigationBar.barStyle = accountsViewController.navigationController.navigationBar.barStyle;
- }
-
- [accountsViewController presentModalViewController:nav animated:YES];
- });
-
- }
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ [self showPasscodeLockIfNeeded];
+}
+
+- (void)showPasscodeLockIfNeeded
+{
+ if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
+
+ KKPasscodeViewController *vc = [[[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil] autorelease];
+ vc.mode = KKPasscodeModeEnter;
+ vc.delegate = self;
+
+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ nav.modalPresentationStyle = UIModalPresentationFullScreen;
+ nav.navigationBar.barStyle = UIBarStyleBlack;
+ nav.navigationBar.opaque = NO;
+ } else {
+ nav.navigationBar.tintColor = accountsViewController.navigationController.navigationBar.tintColor;
+ nav.navigationBar.translucent = accountsViewController.navigationController.navigationBar.translucent;
+ nav.navigationBar.opaque = accountsViewController.navigationController.navigationBar.opaque;
+ nav.navigationBar.barStyle = accountsViewController.navigationController.navigationBar.barStyle;
+ }
+ UIViewController *viewControllerForPresentingPasscode = nil;
+ if (self.window.rootViewController.modalViewController) {
+ if ([self.window.rootViewController.modalViewController isKindOfClass:[UINavigationController class]]
+ && [[[(UINavigationController *)self.window.rootViewController.modalViewController viewControllers] objectAtIndex:0] isKindOfClass:[KKPasscodeViewController class]]) {
+ //The passcode dialog is already shown...
+ return;
+ }
+ //We're in the settings or add account dialog...
+ viewControllerForPresentingPasscode = self.window.rootViewController.modalViewController;
+ } else {
+ viewControllerForPresentingPasscode = self.window.rootViewController;
+ }
+ if (self.accountsPopover.popoverVisible) {
+ [self.accountsPopover dismissPopoverAnimated:NO];
+ }
+ [[NSNotificationCenter defaultCenter] postNotificationName:ASWillShowPasscodeLockNotification object:self];
+ [viewControllerForPresentingPasscode presentModalViewController:nav animated:NO];
+ }
}
- (void)applicationWillTerminate:(UIApplication *)application
@@ -30,6 +30,8 @@
UIActivityIndicatorView *activityIndicator;
UILabel *statusLabel;
UIProgressView *progressBar;
+
+ UIActionSheet *activeSheet;
}
@property (nonatomic, retain) ASAccount *account;
@@ -45,8 +47,10 @@
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, retain) UILabel *statusLabel;
@property (nonatomic, retain) UIProgressView *progressBar;
+@property (nonatomic, retain) UIActionSheet *activeSheet;
- (id)initWithAccount:(ASAccount *)anAccount;
+- (void)willShowPasscodeLock:(NSNotification *)notification;
- (NSSet *)entityNamesTriggeringReload;
- (void)reloadData;
- (void)reloadTableView;
@@ -17,7 +17,7 @@ @implementation DashboardViewController
@synthesize account, products, visibleProducts, selectedProduct;
@synthesize productsTableView, topView, shadowView, colorPopover, statusToolbar, stopButtonItem, activityIndicator, statusLabel, progressBar;
-
+@synthesize activeSheet;
- (id)initWithAccount:(ASAccount *)anAccount
{
@@ -26,10 +26,21 @@ - (id)initWithAccount:(ASAccount *)anAccount
self.account = anAccount;
self.hidesBottomBarWhenPushed = [[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextDidChange:) name:NSManagedObjectContextObjectsDidChangeNotification object:[account managedObjectContext]];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willShowPasscodeLock:) name:ASWillShowPasscodeLockNotification object:nil];
}
return self;
}
+- (void)willShowPasscodeLock:(NSNotification *)notification
+{
+ if (self.colorPopover.popoverVisible) {
+ [self.colorPopover dismissPopoverAnimated:NO];
+ }
+ if (self.activeSheet.visible) {
+ [self.activeSheet dismissWithClickedButtonIndex:self.activeSheet.cancelButtonIndex animated:NO];
+ }
+}
+
- (void)contextDidChange:(NSNotification *)notification
{
NSSet *relevantEntityNames = [self entityNamesTriggeringReload];
@@ -362,6 +373,7 @@ - (void)dealloc
[statusLabel release];
[progressBar release];
[colorPopover release];
+ [activeSheet release];
[super dealloc];
}
View
@@ -18,6 +18,7 @@
#import <Foundation/Foundation.h>
@interface KKKeychain : NSObject {
+
}
+ (BOOL)setString:(NSString*)string forKey:(NSString*)key;
View
@@ -18,34 +18,28 @@
#import "KKKeychain.h"
#import <Security/Security.h>
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation KKKeychain
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-+ (NSString*)appName {
++ (NSString*)appName
+{
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
-
NSString *appName = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
if (!appName) {
appName = [bundle objectForInfoDictionaryKey:@"CFBundleName"];
}
- return appName;
+ return appName;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-+ (BOOL)setString:(NSString*)string forKey:(NSString*)key {
++ (BOOL)setString:(NSString*)string forKey:(NSString*)key
+{
if (string == nil || key == nil) {
return NO;
}
+
+ key = [NSString stringWithFormat:@"%@ - %@", [KKKeychain appName], key];
- key = [NSString stringWithFormat:@"%@ - %@", [KKKeychain appName], key];
-
- // First check if it already exists, by creating a search dictionary and requesting that
- // nothing be returned, and performing the search anyway.
+ // First check if it already exists, by creating a search dictionary and requesting that
+ // nothing be returned, and performing the search anyway.
NSMutableDictionary *existsQueryDictionary = [NSMutableDictionary dictionary];
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
@@ -69,25 +63,18 @@ + (BOOL)setString:(NSString*)string forKey:(NSString*)key {
// Modify an existing one
// Actually pull it now of the keychain at this point.
NSDictionary *attributeDict = [NSDictionary dictionaryWithObject:data forKey:(id)kSecValueData];
-
res = SecItemUpdate((CFDictionaryRef)existsQueryDictionary, (CFDictionaryRef)attributeDict);
NSAssert1(res == errSecSuccess, @"SecItemUpdated returned %d!", res);
-
} else {
NSAssert1(NO, @"Received %d from SecItemCopyMatching!", res);
}
-
return YES;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-+ (NSString*)getStringForKey:(NSString*)key {
-
- key = [NSString stringWithFormat:@"%@ - %@", [KKKeychain appName], key];
-
++ (NSString*)getStringForKey:(NSString*)key
+{
+ key = [NSString stringWithFormat:@"%@ - %@", [KKKeychain appName], key];
NSMutableDictionary *existsQueryDictionary = [NSMutableDictionary dictionary];
-
[existsQueryDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
// Add the keys to the search dict
@@ -112,5 +99,4 @@ + (NSString*)getStringForKey:(NSString*)key {
}
-
@end
View
@@ -6,7 +6,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,8 +19,8 @@
#import "KKPasscodeViewController.h"
@interface KKPasscodeLock : NSObject {
- BOOL _eraseOption;
- NSUInteger _attemptsAllowed;
+ BOOL _eraseOption;
+ NSUInteger _attemptsAllowed;
}
+ (KKPasscodeLock*)sharedLock;
Oops, something went wrong.

0 comments on commit fd918a9

Please sign in to comment.