Permalink
Browse files

passcode lock support

using KKPasscodeLock
  • Loading branch information...
1 parent 0ea37da commit 774a4d0adfa6d2b44185a4e0b2ee7825e895f7f5 @aporat aporat committed Jan 21, 2012
@@ -7,6 +7,14 @@
objects = {
/* Begin PBXBuildFile section */
+ 6D81575414CB3C2B005E8F3F /* KKKeychain.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D81574914CB3C2B005E8F3F /* KKKeychain.m */; };
+ 6D81575514CB3C2B005E8F3F /* KKPasscodeLock.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D81574B14CB3C2B005E8F3F /* KKPasscodeLock.m */; };
+ 6D81575614CB3C2B005E8F3F /* KKPasscodeSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D81574D14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.m */; };
+ 6D81575714CB3C2B005E8F3F /* KKPasscodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D81574F14CB3C2B005E8F3F /* KKPasscodeViewController.m */; };
+ 6D81576514CB44BE005E8F3F /* passcode_square_empty.png in Resources */ = {isa = PBXBuildFile; fileRef = 6D81576114CB44BE005E8F3F /* passcode_square_empty.png */; };
+ 6D81576614CB44BE005E8F3F /* passcode_square_empty@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 6D81576214CB44BE005E8F3F /* passcode_square_empty@2x.png */; };
+ 6D81576714CB44BE005E8F3F /* passcode_square_filled.png in Resources */ = {isa = PBXBuildFile; fileRef = 6D81576314CB44BE005E8F3F /* passcode_square_filled.png */; };
+ 6D81576814CB44BE005E8F3F /* passcode_square_filled@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 6D81576414CB44BE005E8F3F /* passcode_square_filled@2x.png */; };
7F06B6BF13BF73C8004DB170 /* Report.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F06B6BE13BF73C8004DB170 /* Report.m */; };
7F0B8A6913F77F95006E9151 /* PromoCodeOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F0B8A6813F77F95006E9151 /* PromoCodeOperation.m */; };
7F0B8A6E13F7B941006E9151 /* PromoCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F0B8A6D13F7B941006E9151 /* PromoCode.m */; };
@@ -637,6 +645,18 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ 6D81574814CB3C2B005E8F3F /* KKKeychain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KKKeychain.h; sourceTree = "<group>"; };
+ 6D81574914CB3C2B005E8F3F /* KKKeychain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KKKeychain.m; sourceTree = "<group>"; };
+ 6D81574A14CB3C2B005E8F3F /* KKPasscodeLock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KKPasscodeLock.h; sourceTree = "<group>"; };
+ 6D81574B14CB3C2B005E8F3F /* KKPasscodeLock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KKPasscodeLock.m; sourceTree = "<group>"; };
+ 6D81574C14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KKPasscodeSettingsViewController.h; sourceTree = "<group>"; };
+ 6D81574D14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KKPasscodeSettingsViewController.m; sourceTree = "<group>"; };
+ 6D81574E14CB3C2B005E8F3F /* KKPasscodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KKPasscodeViewController.h; sourceTree = "<group>"; };
+ 6D81574F14CB3C2B005E8F3F /* KKPasscodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KKPasscodeViewController.m; sourceTree = "<group>"; };
+ 6D81576114CB44BE005E8F3F /* passcode_square_empty.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = passcode_square_empty.png; sourceTree = "<group>"; };
+ 6D81576214CB44BE005E8F3F /* passcode_square_empty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "passcode_square_empty@2x.png"; sourceTree = "<group>"; };
+ 6D81576314CB44BE005E8F3F /* passcode_square_filled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = passcode_square_filled.png; sourceTree = "<group>"; };
+ 6D81576414CB44BE005E8F3F /* passcode_square_filled@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "passcode_square_filled@2x.png"; sourceTree = "<group>"; };
7F06B6BD13BF73C8004DB170 /* Report.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Report.h; sourceTree = "<group>"; };
7F06B6BE13BF73C8004DB170 /* Report.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Report.m; sourceTree = "<group>"; };
7F0B8A6713F77F95006E9151 /* PromoCodeOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PromoCodeOperation.h; sourceTree = "<group>"; };
@@ -1487,6 +1507,10 @@
7F709D6F13BCCB8B0008DBAD /* Images */ = {
isa = PBXGroup;
children = (
+ 6D81576114CB44BE005E8F3F /* passcode_square_empty.png */,
+ 6D81576214CB44BE005E8F3F /* passcode_square_empty@2x.png */,
+ 6D81576314CB44BE005E8F3F /* passcode_square_filled.png */,
+ 6D81576414CB44BE005E8F3F /* passcode_square_filled@2x.png */,
7F15452F14223FFA00D74A18 /* Default-Portrait~ipad.png */,
7F2E75D114237F2500793375 /* Default-Landscape~ipad.png */,
7FAEB66813E6D1AF00750788 /* Badge.png */,
@@ -1653,6 +1677,14 @@
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 */,
@@ -2842,6 +2874,10 @@
7F0B8A7013F7C0EC006E9151 /* RequestPromoCode.png in Resources */,
7F15453014223FFA00D74A18 /* Default-Portrait~ipad.png in Resources */,
7F2E75D214237F2500793375 /* Default-Landscape~ipad.png in Resources */,
+ 6D81576514CB44BE005E8F3F /* passcode_square_empty.png in Resources */,
+ 6D81576614CB44BE005E8F3F /* passcode_square_empty@2x.png in Resources */,
+ 6D81576714CB44BE005E8F3F /* passcode_square_filled.png in Resources */,
+ 6D81576814CB44BE005E8F3F /* passcode_square_filled@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2910,6 +2946,10 @@
7F0B8A6E13F7B941006E9151 /* PromoCode.m in Sources */,
7F0B8A7313F7E647006E9151 /* PromoCodesLicenseViewController.m in Sources */,
7F26689714055D2200FD2CC5 /* AccountsViewController+VendorID.m in Sources */,
+ 6D81575414CB3C2B005E8F3F /* KKKeychain.m in Sources */,
+ 6D81575514CB3C2B005E8F3F /* KKPasscodeLock.m in Sources */,
+ 6D81575614CB3C2B005E8F3F /* KKPasscodeSettingsViewController.m in Sources */,
+ 6D81575714CB3C2B005E8F3F /* KKPasscodeViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -8,6 +8,7 @@
#import <UIKit/UIKit.h>
#import "FieldEditorViewController.h"
+#import "KKPasscodeSettingsViewController.h"
#define kAccountUsername @"username"
#define kAccountPassword @"password"
@@ -17,13 +18,17 @@
@class ASAccount;
@protocol AccountsViewControllerDelegate;
-@interface AccountsViewController : UITableViewController <NSFetchedResultsControllerDelegate, UIAlertViewDelegate, FieldEditorViewControllerDelegate>
+@interface AccountsViewController : UITableViewController <NSFetchedResultsControllerDelegate, UIAlertViewDelegate, FieldEditorViewControllerDelegate, KKPasscodeSettingsViewControllerDelegate>
{
id<AccountsViewControllerDelegate> delegate;
NSArray *accounts;
NSManagedObjectContext *managedObjectContext;
ASAccount *selectedAccount;
UIBarButtonItem *refreshButtonItem;
+
+ FieldSpecifier *passcodeLockField;
+ FieldEditorViewController *settingsViewController;
+ UINavigationController *settingsNavController;
}
@property (nonatomic, assign) id<AccountsViewControllerDelegate> delegate;
@@ -24,11 +24,13 @@
#import "AccountStatusView.h"
#import "PromoCodesViewController.h"
#import "PromoCodesLicenseViewController.h"
+#import "KKPasscodeLock.h"
#define kAddNewAccountEditorIdentifier @"AddNewAccountEditorIdentifier"
#define kEditAccountEditorIdentifier @"EditAccountEditorIdentifier"
#define kSettingsEditorIdentifier @"SettingsEditorIdentifier"
#define kUpdateExchangeRatesButton @"UpdateExchangeRatesButton"
+#define kPasscodeLockButton @"PasscodeLockButton"
#define kImportReportsButton @"ImportReportsButton"
#define kExportReportsButton @"ExportReportsButton"
#define kDownloadBoxcarButton @"DownloadBoxcarButton"
@@ -394,6 +396,13 @@ - (void)editAccount:(ASAccount *)account
- (void)showSettings
{
// main section
+ passcodeLockField = [FieldSpecifier buttonFieldWithKey:kPasscodeLockButton title:NSLocalizedString(@"Passcode Lock", nil)];
+ if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
+ passcodeLockField.defaultValue = @"On";
+ } else {
+ passcodeLockField.defaultValue = @"Off";
+ }
+
NSString *baseCurrency = [[CurrencyManager sharedManager] baseCurrency];
NSArray *availableCurrencies = [[CurrencyManager sharedManager] availableCurrencies];
NSMutableArray *currencyFields = [NSMutableArray array];
@@ -408,7 +417,7 @@ - (void)showSettings
FieldSpecifier *currencySectionField = [FieldSpecifier subsectionFieldWithSection:currencySection key:@"currency"];
FieldSpecifier *updateExchangeRatesButtonField = [FieldSpecifier buttonFieldWithKey:kUpdateExchangeRatesButton title:NSLocalizedString(@"Update Exchange Rates Now", nil)];
FieldSpecifier *downloadPaymentsField = [FieldSpecifier switchFieldWithKey:kSettingDownloadPayments title:NSLocalizedString(@"Download Payments", nil) defaultValue:[[NSUserDefaults standardUserDefaults] boolForKey:kSettingDownloadPayments]];
- FieldSectionSpecifier *mainSection = [FieldSectionSpecifier sectionWithFields:[NSArray arrayWithObjects:currencySectionField, updateExchangeRatesButtonField, downloadPaymentsField, nil]
+ FieldSectionSpecifier *mainSection = [FieldSectionSpecifier sectionWithFields:[NSArray arrayWithObjects:passcodeLockField, currencySectionField, updateExchangeRatesButtonField, downloadPaymentsField, nil]
title:NSLocalizedString(@"General", nil)
description:NSLocalizedString(@"Exchange rates will automatically be refreshed periodically.", nil)];
@@ -442,12 +451,12 @@ - (void)showSettings
FieldSectionSpecifier *pushSectionFieldSection = [FieldSectionSpecifier sectionWithFields:[NSArray arrayWithObject:pushSectionField] title:NSLocalizedString(@"Push Notifications", nil) description:nil];
NSArray *sections = [NSArray arrayWithObjects:mainSection, productsSection, pushSectionFieldSection, nil];
- FieldEditorViewController *settingsViewController = [[[FieldEditorViewController alloc] initWithFieldSections:sections title:NSLocalizedString(@"Settings",nil)] autorelease];
+ settingsViewController = [[[FieldEditorViewController alloc] initWithFieldSections:sections title:NSLocalizedString(@"Settings",nil)] autorelease];
settingsViewController.doneButtonTitle = NSLocalizedString(@"Done", nil);
settingsViewController.delegate = self;
settingsViewController.editorIdentifier = kSettingsEditorIdentifier;
- UINavigationController *settingsNavController = [[[UINavigationController alloc] initWithRootViewController:settingsViewController] autorelease];
+ settingsNavController = [[[UINavigationController alloc] initWithRootViewController:settingsViewController] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
settingsNavController.modalPresentationStyle = UIModalPresentationFormSheet;
}
@@ -532,7 +541,12 @@ - (void)fieldEditor:(FieldEditorViewController *)editor didFinishEditingWithValu
- (void)fieldEditor:(FieldEditorViewController *)editor pressedButtonWithKey:(NSString *)key
{
- if ([key isEqualToString:kUpdateExchangeRatesButton]) {
+
+ if ([key isEqualToString:kPasscodeLockButton]) {
+ KKPasscodeSettingsViewController *vc = [[[KKPasscodeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
+ vc.delegate = self;
+ [settingsNavController pushViewController:vc animated:YES];
+ } else if ([key isEqualToString:kUpdateExchangeRatesButton]) {
[[CurrencyManager sharedManager] forceRefresh];
} else if ([key isEqualToString:kImportReportsButton]) {
ASAccount *account = (ASAccount *)editor.context;
@@ -692,6 +706,18 @@ - (void)fieldEditorDidCancel:(FieldEditorViewController *)editor
[editor dismissModalViewControllerAnimated:YES];
}
+- (void)didSettingsChanged:(KKPasscodeSettingsViewController*)viewController
+{
+
+ if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
+ passcodeLockField.defaultValue = @"On";
+ } else {
+ passcodeLockField.defaultValue = @"Off";
+ }
+
+ [settingsViewController.tableView reloadData];
+}
+
#pragma mark -
- (void)saveContext
@@ -8,10 +8,11 @@
#import <UIKit/UIKit.h>
#import "AccountsViewController.h"
+#import "KKPasscodeLock.h"
@class ASAccount;
-@interface AppSalesAppDelegate : NSObject <UIApplicationDelegate, UIActionSheetDelegate, AccountsViewControllerDelegate>
+@interface AppSalesAppDelegate : NSObject <UIApplicationDelegate, UIActionSheetDelegate, AccountsViewControllerDelegate, KKPasscodeViewControllerDelegate>
{
UIWindow *window;
@@ -26,6 +26,9 @@ @implementation AppSalesAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
+ [[KKPasscodeLock sharedLock] setDefaultSettings];
+ [[KKPasscodeLock sharedLock] setEraseOption:NO];
+
srandom(time(NULL));
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
@@ -205,6 +208,30 @@ - (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)applicationWillTerminate:(UIApplication *)application
@@ -320,6 +320,9 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce
}
}
}
+ if (field.type == FieldSpecifierTypeButton) {
+ cell.detailTextLabel.text = field.defaultValue;
+ }
if (field.type == FieldSpecifierTypeButton && field.shouldDisplayDisclosureIndicator) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
@@ -576,7 +579,6 @@ + (FieldSpecifier *)buttonFieldWithKey:(NSString *)k title:(NSString *)buttonTit
{
FieldSpecifier *field = [FieldSpecifier fieldWithType:FieldSpecifierTypeButton key:k];
field.title = buttonTitle;
- field.defaultValue = @"";
return field;
}
View
@@ -0,0 +1,27 @@
+//
+// Copyright 2011-2012 Kosher Penguin LLC
+// Created by Adar Porat (https://github.com/aporat) on 1/16/2012.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// 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
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface KKKeychain : NSObject {
+}
+
++ (BOOL)setString:(NSString*)string forKey:(NSString*)key;
+
++ (NSString*)getStringForKey:(NSString*)key;
+
+@end
Oops, something went wrong.

0 comments on commit 774a4d0

Please sign in to comment.