Skip to content

Commit

Permalink
Fix TouchID issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jCalaU committed Apr 22, 2015
1 parent 84fec56 commit 13526e9
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Classes/CongratulationsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import <UIKit/UIKit.h>
#import "GAITrackedViewController.h"

@interface CongratulationsController : GAITrackedViewController {
@interface CongratulationsController : GAITrackedViewController <UIAlertViewDelegate> {

UILabel *congratsTitle;
UILabel *congratsMsg;
Expand Down
28 changes: 28 additions & 0 deletions Classes/CongratulationsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#import "LoginController.h"
#import "PhotoController.h"
#import "Constants.h"
#import <LocalAuthentication/LocalAuthentication.h>
#import "PreyConfig.h"

@implementation CongratulationsController

Expand Down Expand Up @@ -78,6 +80,9 @@ - (void)viewDidLoad

// Authorization Camera
[PhotoController instance];

// Check TouchID
[self checkTouchID];
}
else
{
Expand All @@ -88,6 +93,29 @@ - (void)viewDidLoad
[super viewDidLoad];
}

- (void)checkTouchID
{
LAContext *context = [[LAContext alloc] init];
NSError *errorCxt = nil;

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&errorCxt])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Information",nil)
message:NSLocalizedString(@"Would you like to use Touch ID to access the Prey settings?",nil)
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel",nil)
otherButtonTitles:NSLocalizedString(@"OK",nil),nil];
[alert show];
}
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[PreyConfig instance].isTouchIDEnabled = YES;
}
}

- (void)viewWillAppear:(BOOL)animated {
/*
self.title = @"Congratulations";
Expand Down
8 changes: 6 additions & 2 deletions Classes/LoginController.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ - (IBAction)goToSettings:(UIButton *)sender
{
[self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width, 0) animated:YES];

if (IS_OS_8_OR_LATER)
if ( (IS_OS_8_OR_LATER) && ([PreyConfig instance].isTouchIDEnabled) )
[self loginWithTouchID];
}

Expand All @@ -172,7 +172,11 @@ - (void)loginWithTouchID
reply:^(BOOL success, NSError *error) {

if (success)
[self showPreferencesController];
{
dispatch_async(dispatch_get_main_queue(), ^{
[self showPreferencesController];
});
}

else if (error.code != kLAErrorUserCancel)
{
Expand Down
35 changes: 34 additions & 1 deletion Classes/PreferencesController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "RecoveriesViewController.h"
#import "UIDevice-Reachability.h"
#import "OnboardingView.h"
#import <LocalAuthentication/LocalAuthentication.h>

@interface UIActionSheet(DismissAlert)
- (void)hide;
Expand Down Expand Up @@ -68,7 +69,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return numberRow;
break;
case 1:
return 2;
return [self isTouchIDAvailable] ? 3 : 2;
break;
case 2:
return 4;
Expand Down Expand Up @@ -193,6 +194,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.accessoryView = nil;
}
else if ([indexPath row] == 2) {
UISwitch *touchIDMode = [[UISwitch alloc]init];
cell.textLabel.text = NSLocalizedString(@"Touch ID",nil);
[touchIDMode addTarget: self action: @selector(touchIDModeState:) forControlEvents:UIControlEventValueChanged];
[touchIDMode setOn:config.isTouchIDEnabled];
cell.accessoryView = touchIDMode;
}

break;
case 2:
cell.detailTextLabel.text = @"";
Expand Down Expand Up @@ -337,6 +346,10 @@ - (IBAction)camouflageModeState:(UISwitch*)camouflageModeSwitch{
[[PreyConfig instance] setCamouflageMode:camouflageModeSwitch.on];
}

- (IBAction)touchIDModeState:(UISwitch*)touchIDModeSwitch{
[[PreyConfig instance] setIsTouchIDEnabled:touchIDModeSwitch.on];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == 1)
Expand Down Expand Up @@ -391,6 +404,26 @@ - (void) detachDevice
}];
}

#pragma mark -
#pragma mark Touch ID

- (BOOL)isTouchIDAvailable
{
BOOL isAvailable = NO;

if (IS_OS_8_OR_LATER)
{
LAContext *context = [[LAContext alloc] init];
NSError *errorCxt = nil;

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&errorCxt])
isAvailable = YES;
}

return isAvailable;
}


#pragma mark -
#pragma mark Events received

Expand Down
2 changes: 2 additions & 0 deletions Classes/PreyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
BOOL camouflageMode;
BOOL intervalMode;
BOOL isNotificationSettingsEnabled;
BOOL isTouchIDEnabled;
}

@property (nonatomic) NSString *checkUrl;
Expand All @@ -47,6 +48,7 @@
@property (nonatomic) BOOL intervalMode;
@property (nonatomic) BOOL alertOnReport;
@property (nonatomic) BOOL isNotificationSettingsEnabled;
@property (nonatomic) BOOL isTouchIDEnabled;
@property (nonatomic) int delay;
@property (getter = isPro) BOOL pro;

Expand Down
31 changes: 18 additions & 13 deletions Classes/PreyConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,34 @@
static NSString *const INTERVAL_MODE=@"interval_mode";
static NSString *const PRO_ACCOUNT=@"pro_account";
static NSString *const NOTIFICATION_SETTINGS=@"notification_settings";
static NSString *const TOUCH_ID=@"touch_id";

@implementation PreyConfig

@synthesize checkUrl, controlPanelHost, checkPath, exceptionsEndpoint, dataEndpoint, apiKey, deviceKey, email, isNotificationSettingsEnabled;
@synthesize desiredAccuracy,alertOnReport,sendCrashReports,delay,alreadyRegistered,missing,askForPassword,camouflageMode,intervalMode,pro;
@synthesize isTouchIDEnabled;

+ (PreyConfig *)instance {
static PreyConfig *instance = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
instance = [[PreyConfig alloc] init];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
instance.controlPanelHost = [defaults stringForKey: CONTROL_PANEL_HOST];
instance.checkPath = [defaults stringForKey: CHECK_PATH];
instance.sendCrashReports = [defaults boolForKey: SEND_CRASH_REPORTS];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
instance.controlPanelHost = [defaults stringForKey: CONTROL_PANEL_HOST];
instance.checkPath = [defaults stringForKey: CHECK_PATH];
instance.sendCrashReports = [defaults boolForKey: SEND_CRASH_REPORTS];
instance.exceptionsEndpoint = [defaults stringForKey: EXCEPTIONS_ENDPOINT];
instance.dataEndpoint = [defaults stringForKey: DATA_ENDPOINT_LOCATION];
instance.dataEndpoint = [defaults stringForKey: DATA_ENDPOINT_LOCATION];

instance.apiKey = [defaults stringForKey: API_KEY];
instance.deviceKey = [defaults stringForKey: DEVICE_KEY];
instance.email = [defaults stringForKey: EMAIL];
instance.camouflageMode = [defaults boolForKey:CAMOUFLAGE_MODE];
instance.apiKey = [defaults stringForKey: API_KEY];
instance.deviceKey = [defaults stringForKey: DEVICE_KEY];
instance.email = [defaults stringForKey: EMAIL];
instance.camouflageMode = [defaults boolForKey:CAMOUFLAGE_MODE];
instance.isNotificationSettingsEnabled = [defaults boolForKey:NOTIFICATION_SETTINGS];
instance.intervalMode = [defaults boolForKey:INTERVAL_MODE];
instance.pro = [defaults boolForKey:PRO_ACCOUNT];
instance.intervalMode = [defaults boolForKey:INTERVAL_MODE];
instance.pro = [defaults boolForKey:PRO_ACCOUNT];
instance.isTouchIDEnabled = [defaults boolForKey:TOUCH_ID];
[instance loadDefaultValues];
});

Expand Down Expand Up @@ -140,7 +143,8 @@ - (void) saveValues
[defaults setBool:[self camouflageMode] forKey:CAMOUFLAGE_MODE];
[defaults setBool:[self intervalMode] forKey:INTERVAL_MODE];
[defaults setBool:[self isNotificationSettingsEnabled] forKey:NOTIFICATION_SETTINGS];
[defaults synchronize]; // this method is optional
[defaults setBool:[self isTouchIDEnabled] forKey:TOUCH_ID];
[defaults synchronize]; // this method is optional
}

-(void)resetValues
Expand All @@ -163,7 +167,8 @@ -(void)resetValues
[defaults removeObjectForKey:CAMOUFLAGE_MODE];
[defaults removeObjectForKey:INTERVAL_MODE];
[defaults removeObjectForKey:NOTIFICATION_SETTINGS];
[defaults synchronize]; // this method is optional
[defaults removeObjectForKey:TOUCH_ID];
[defaults synchronize]; // this method is optional

[[PreyConfig instance] setEmail:nil];
[[PreyConfig instance] setAlreadyRegistered:NO];
Expand Down
4 changes: 3 additions & 1 deletion Localizable.strings/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,6 @@

"Log In" = "Log In";

"Name can't be blank" = "Name can't be blank";
"Name can't be blank" = "Name can't be blank";

"Would you like to use Touch ID to access the Prey settings?" = "Would you like to use Touch ID to access the Prey settings?";
5 changes: 4 additions & 1 deletion Localizable.strings/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,7 @@

"Log In" = "Ingresar";

"Name can't be blank" = "El nombre no puede estar en blanco";
"Name can't be blank" = "El nombre no puede estar en blanco";

"Would you like to use Touch ID to access the Prey settings?" = "¿Te gustaría usar Touch ID para acceder a la configuración de Prey?";

0 comments on commit 13526e9

Please sign in to comment.