forked from soffes/cheddar-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDIAppDelegate.m
174 lines (137 loc) · 7.88 KB
/
CDIAppDelegate.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
// CDIAppDelegate.m
// Cheddar for iOS
//
// Created by Sam Soffes on 3/25/12.
// Copyright (c) 2012 Nothing Magical. All rights reserved.
//
#import "CDIAppDelegate.h"
#import "CDISplitViewController.h"
#import "CDIListsViewController.h"
#import "CDITransactionObserver.h"
#import "CDIDefines.h"
#import "CDISettingsTapPickerViewController.h"
#import "CDISettingsFontPickerViewController.h"
#import "CDISettingsTextSizePickerViewController.h"
#import "UIFont+CheddariOSAdditions.h"
#import "LocalyticsUtilities.h"
#import <Crashlytics/Crashlytics.h>
#import <StoreKit/StoreKit.h>
@implementation CDIAppDelegate
@synthesize window = _window;
+ (CDIAppDelegate *)sharedAppDelegate {
return (CDIAppDelegate *)[[UIApplication sharedApplication] delegate];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Configure analytics
// If you don't work at Nothing Magical, you shouldn't turn these on.
#if CHEDDAR_PRODUCTION_MODE
#ifdef CHEDDAR_CRASHLYTICS_KEY
[Crashlytics startWithAPIKey:CHEDDAR_CRASHLYTICS_KEY];
#endif
#ifdef CHEDDAR_LOCALYTICS_KEY
LLStartSession(CHEDDAR_LOCALYTICS_KEY);
#endif
#endif
// Optionally enable development mode
// If you don't work at Nothing Magical, you shouldn't turn this on.
#ifdef CHEDDAR_API_DEVELOPMENT_MODE
[CDKHTTPClient setDevelopmentModeEnabled:YES];
[CDKPushController setDevelopmentModeEnabled:YES];
#endif
// Default defaults
NSDictionary *defaults = @{
kCDITapActionDefaultsKey: kCDITapActionCompleteKey,
kCDIFontDefaultsKey: kCDIFontGothamKey,
kCDITextSizeDefaultsKey: kCDITextSizeMediumKey
};
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
// Initialize the window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor blackColor];
[self applyStylesheet];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.window.rootViewController = [[CDISplitViewController alloc] init];
} else {
UIViewController *viewController = [[CDIListsViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = navigationController;
}
[self.window makeKeyAndVisible];
// Defer some stuff to make launching faster
dispatch_async(dispatch_get_main_queue(), ^{
// Setup status bar network indicator
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
// Set the OAuth client
[[CDKHTTPClient sharedClient] setClientID:kCDIAPIClientID secret:kCDIAPIClientSecret];
// Initialize the connection to Pusher
[CDKPushController sharedController];
// Add the transaction observer
[[SKPaymentQueue defaultQueue] addTransactionObserver:[CDITransactionObserver defaultObserver]];
});
return YES;
}
#if ANALYTICS_ENABLED
- (void)applicationWillEnterForeground:(UIApplication *)application {
[[LocalyticsSession sharedLocalyticsSession] resume];
[[LocalyticsSession sharedLocalyticsSession] upload];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[LocalyticsSession sharedLocalyticsSession] close];
[[LocalyticsSession sharedLocalyticsSession] upload];
}
#endif
- (void)applicationWillTerminate:(UIApplication *)application {
[[SSManagedObject mainContext] save:nil];
#if ANALYTICS_ENABLED
[[LocalyticsSession sharedLocalyticsSession] close];
#endif
}
#pragma mark - Stylesheet
- (void)applyStylesheet {
// Navigation bar
UINavigationBar *navigationBar = [UINavigationBar appearance];
[navigationBar setBackgroundImage:[UIImage imageNamed:@"nav-background"] forBarMetrics:UIBarMetricsDefault];
[navigationBar setTitleVerticalPositionAdjustment:-1.0f forBarMetrics:UIBarMetricsDefault];
[navigationBar setTitleTextAttributes:[[NSDictionary alloc] initWithObjectsAndKeys:
[UIFont cheddarInterfaceFontOfSize:20.0f], UITextAttributeFont,
[UIColor colorWithWhite:0.0f alpha:0.2f], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
[UIColor whiteColor], UITextAttributeTextColor,
nil]];
// Navigation bar mini
[navigationBar setTitleVerticalPositionAdjustment:-2.0f forBarMetrics:UIBarMetricsLandscapePhone];
[navigationBar setBackgroundImage:[UIImage imageNamed:@"nav-background-mini"] forBarMetrics:UIBarMetricsLandscapePhone];
// Navigation button
NSDictionary *barButtonTitleTextAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[UIFont cheddarInterfaceFontOfSize:14.0f], UITextAttributeFont,
[UIColor colorWithWhite:0.0f alpha:0.2f], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil];
UIBarButtonItem *barButton = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil];
// [barButton setTitlePositionAdjustment:UIOffsetMake(0.0f, 1.0f) forBarMetrics:UIBarMetricsDefault];
[barButton setTitleTextAttributes:barButtonTitleTextAttributes forState:UIControlStateNormal];
[barButton setTitleTextAttributes:barButtonTitleTextAttributes forState:UIControlStateHighlighted];
[barButton setBackgroundImage:[[UIImage imageNamed:@"nav-button"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barButton setBackgroundImage:[[UIImage imageNamed:@"nav-button-highlighted"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
// Navigation back button
[barButton setBackButtonTitlePositionAdjustment:UIOffsetMake(2.0f, -2.0f) forBarMetrics:UIBarMetricsDefault];
[barButton setBackButtonBackgroundImage:[[UIImage imageNamed:@"nav-back"] stretchableImageWithLeftCapWidth:13 topCapHeight:0] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barButton setBackButtonBackgroundImage:[[UIImage imageNamed:@"nav-back-highlighted"] stretchableImageWithLeftCapWidth:13 topCapHeight:0] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
// Navigation button mini
// [barButton setTitlePositionAdjustment:UIOffsetMake(0.0f, 1.0f) forBarMetrics:UIBarMetricsLandscapePhone];
[barButton setBackgroundImage:[[UIImage imageNamed:@"nav-button-mini"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
[barButton setBackgroundImage:[[UIImage imageNamed:@"nav-button-mini-highlighted"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] forState:UIControlStateHighlighted barMetrics:UIBarMetricsLandscapePhone];
// Navigation back button mini
[barButton setBackButtonTitlePositionAdjustment:UIOffsetMake(2.0f, -2.0f) forBarMetrics:UIBarMetricsLandscapePhone];
[barButton setBackButtonBackgroundImage:[[UIImage imageNamed:@"nav-back-mini"] stretchableImageWithLeftCapWidth:10 topCapHeight:0] forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
[barButton setBackButtonBackgroundImage:[[UIImage imageNamed:@"nav-back-mini-highlighted"] stretchableImageWithLeftCapWidth:10 topCapHeight:0] forState:UIControlStateHighlighted barMetrics:UIBarMetricsLandscapePhone];
// Toolbar
UIToolbar *toolbar = [UIToolbar appearance];
[toolbar setBackgroundImage:[UIImage imageNamed:@"navigation-background"] forToolbarPosition:UIToolbarPositionTop barMetrics:UIBarMetricsDefault];
[toolbar setBackgroundImage:[UIImage imageNamed:@"toolbar-background"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault];
// Toolbar mini
[toolbar setBackgroundImage:[UIImage imageNamed:@"navigation-background-mini"] forToolbarPosition:UIToolbarPositionTop barMetrics:UIBarMetricsLandscapePhone];
[toolbar setBackgroundImage:[UIImage imageNamed:@"toolbar-background-mini"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsLandscapePhone];
}
@end