-
Notifications
You must be signed in to change notification settings - Fork 106
/
SMSNinjaApplication.m
126 lines (109 loc) · 4.94 KB
/
SMSNinjaApplication.m
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
120
121
122
123
124
125
126
#import "SMSNinjaApplication.h"
#import <objc/runtime.h>
#ifndef SMSNinjaDebug
#define SETTINGS @"/var/mobile/Library/SMSNinja/smsninja.plist"
#else
#define SETTINGS @"/Users/snakeninny/Library/Application Support/iPhone Simulator/7.0.3/Applications/0C9D35FB-B626-42B7-AAE9-45F6F537890B/Documents/var/mobile/Library/SMSNinja/smsninja.plist"
#endif
static SMSNinjaApplication *currentApplication;
static void QuitApp(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
[currentApplication applicationWillTerminate:currentApplication];
[currentApplication terminateWithSuccess];
}
@implementation SMSNinjaApplication
@synthesize window = _window;
- (void)dealloc
{
[_window release];
_window = nil;
[_viewController release];
_viewController = nil;
[navigationController release];
navigationController = nil;
[super dealloc];
}
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_viewController = [[SNMainViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[self showPasswordAlert];
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, QuitApp, CFSTR("com.naken.smsninja.willlock"), NULL, CFNotificationSuspensionBehaviorCoalesce); // for iOS 6
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, QuitApp, CFSTR("com.apple.springboard.lockcomplete"), NULL, CFNotificationSuspensionBehaviorCoalesce); // for iOS 5, 7 & 8
currentApplication = self;
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[self updateBadgeAndSquareAndIcon];
CPDistributedMessagingCenter *messagingCenter = [objc_getClass("CPDistributedMessagingCenter") centerNamed:@"com.naken.smsninja.springboard"];
[messagingCenter sendMessageName:@"RemoveIconFromSwitcher" userInfo:nil];
}
- (void)showPasswordAlert
{
if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS] && [[[NSDictionary dictionaryWithContentsOfFile:SETTINGS] objectForKey:@"startPassword"] length] != 0)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Welcome", @"Welcome") message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Let me in!", @"Let me in!") otherButtonTitles:NSLocalizedString(@"Never mind", @"Never mind") , nil];
[alertView setAlertViewStyle:UIAlertViewStyleSecureTextInput];
[alertView show];
[alertView release];
}
else
{
_viewController.fake = nil;
_viewController.fake = @NO;
self.window.rootViewController = navigationController;
[_window makeKeyAndVisible];
}
}
- (void)updateBadgeAndSquareAndIcon
{
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:SETTINGS];
CPDistributedMessagingCenter *messagingCenter = [objc_getClass("CPDistributedMessagingCenter") centerNamed:@"com.naken.smsninja.springboard"];
[messagingCenter sendMessageName:@"UpdateBadge" userInfo:nil];
if ([[dictionary objectForKey:@"appIsOn"] boolValue])
{
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([[dictionary objectForKey:@"shouldShowPurpleSquare"] boolValue] && [fileManager fileExistsAtPath:@"/var/mobile/Library/SMSNinja/UnreadPrivateInfo"]) [messagingCenter sendMessageName:@"ShowPurpleSquare" userInfo:nil];
else [messagingCenter sendMessageName:@"HidePurpleSquare" userInfo:nil];
if ([[dictionary objectForKey:@"shouldHideIcon"] boolValue]) [messagingCenter sendMessageName:@"HideIcon" userInfo:nil];
else [messagingCenter sendMessageName:@"ShowIcon" userInfo:nil];
}
else
{
[messagingCenter sendMessageName:@"HidePurpleSquare" userInfo:nil];
[messagingCenter sendMessageName:@"ShowIcon" userInfo:nil];
}
}
- (void)willPresentAlertView:(UIAlertView *)alertView
{
UITextField *textField = [alertView textFieldAtIndex:0];
textField.placeholder = NSLocalizedString(@"Password here", @"Password here");
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *password = [alertView textFieldAtIndex:0].text;
if (buttonIndex == 0)
{
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:SETTINGS];
if ([[dictionary objectForKey:@"startPassword"] isEqualToString:password] && [password length] != 0)
{
_viewController.fake = nil;
_viewController.fake = @NO;
self.window.rootViewController = navigationController;
[_window makeKeyAndVisible];
}
else if ([[dictionary objectForKey:@"fakePassword"] isEqualToString:password] && [password length] != 0)
{
_viewController.fake = nil;
_viewController.fake = @YES;
self.window.rootViewController = navigationController;
[_window makeKeyAndVisible];
}
else [self terminateWithSuccess];
}
else [self terminateWithSuccess];
}
@end