-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathDMAppDelegate.m
More file actions
119 lines (102 loc) · 4.56 KB
/
Copy pathDMAppDelegate.m
File metadata and controls
119 lines (102 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// DMAppDelegate.m
// DMPasscode
//
// Created by CocoaPods on 09/20/2014.
// Copyright (c) 2014 Dylan Marriott. All rights reserved.
//
#import "DMAppDelegate.h"
#import <DMPasscode/DMPasscode.h>
@implementation DMAppDelegate {
UIViewController* _rootViewController;
UIButton* _setupButton;
UIButton* _checkButton;
UIButton* _removeButton;
BOOL _showingPasscode;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
_rootViewController = [[UIViewController alloc] init];
self.window.rootViewController = _rootViewController;
[self addViews];
[self updateViews];
/*
// Example for a different config.
DMPasscodeConfig* config = [[DMPasscodeConfig alloc] init];
config.navigationBarBackgroundColor = [UIColor colorWithRed:0.10 green:0.34 blue:0.61 alpha:1.00];
config.navigationBarForegroundColor = [UIColor whiteColor];
config.fieldColor = [UIColor colorWithRed:0.10 green:0.34 blue:0.61 alpha:1.00];
config.emptyFieldColor = [UIColor colorWithRed:0.10 green:0.34 blue:0.61 alpha:1.00];
config.statusBarStyle = UIStatusBarStyleLightContent;
[DMPasscode setConfig:config];
*/
return YES;
}
- (void)addViews {
_setupButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 50, _rootViewController.view.frame.size.width, 50)];
[_setupButton setTitle:@"Setup" forState:UIControlStateNormal];
[_setupButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_setupButton addTarget:self action:@selector(actionSetup:) forControlEvents:UIControlEventTouchUpInside];
[_rootViewController.view addSubview:_setupButton];
_checkButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, _rootViewController.view.frame.size.width, 50)];
[_checkButton setTitle:@"Check" forState:UIControlStateNormal];
[_checkButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_checkButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[_checkButton addTarget:self action:@selector(actionCheck:) forControlEvents:UIControlEventTouchUpInside];
[_rootViewController.view addSubview:_checkButton];
_removeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 150, _rootViewController.view.frame.size.width, 50)];
[_removeButton setTitle:@"Remove" forState:UIControlStateNormal];
[_removeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_removeButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[_removeButton addTarget:self action:@selector(actionRemove:) forControlEvents:UIControlEventTouchUpInside];
[_rootViewController.view addSubview:_removeButton];
}
- (void)actionSetup:(UIButton *)sender {
[DMPasscode setupPasscodeInViewController:_rootViewController completion:^(BOOL success, NSError *error) {
[self updateViews];
}];
}
- (void)actionCheck:(UIButton *)sender {
[DMPasscode showPasscodeInViewController:_rootViewController completion:^(BOOL success, NSError *error) {
if (success) {
[sender setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
} else {
if (error) {
// Failed authentication
[sender setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
} else {
// Cancelled
[sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
}
[self updateViews];
}];
}
- (void)actionRemove:(id)sender {
[DMPasscode removePasscode];
[_checkButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self updateViews];
}
- (void)updateViews {
BOOL passcodeSet = [DMPasscode isPasscodeSet];
_checkButton.enabled = passcodeSet;
_removeButton.enabled = passcodeSet;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
if ([DMPasscode isPasscodeSet] && !_showingPasscode) {
_showingPasscode = YES;
[DMPasscode showPasscodeInViewController:self.window.rootViewController completion:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"Win");
}else{
NSLog(@"Loss");
}
}];
}
}
-(void)applicationWillEnterForeground:(UIApplication *)application{
_showingPasscode = NO;
}
@end