1717
1818static NSString * const kAnalyticsTrackingID = @" UA-63011163-1" ;
1919
20- @interface AppDelegate () {
21- DataManager *_dataManager;
22- }
20+ @interface AppDelegate ()
2321
2422@end
2523
@@ -32,35 +30,24 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3230 self.window = [[UIWindow alloc ] initWithFrame: [[UIScreen mainScreen ] bounds ]];
3331 self.window .backgroundColor = [UIColor whiteColor ];
3432
35- _dataManager = [DataManager sharedInstance ];
36-
37- [ThemeManager setupTheme ];
38-
39- [Fabric with: @[CrashlyticsKit]];
33+ application.applicationIconBadgeNumber = 0 ;
4034
41- [self initializeAnalytics ];
35+ [self setupThirdPartyLibraries ];
4236 [self setupPushNotifications ];
43- [self clearAppBadge ];
4437
4538 self.window .rootViewController = [[UINavigationController alloc ] initWithRootViewController: [ComicListViewController new ]];
46-
4739 [self .window makeKeyAndVisible ];
4840
4941 return YES ;
5042}
5143
52- - (void )applicationWillEnterForeground : (UIApplication *)application {
53- [[GTTracker sharedInstance ] startAnalyticsSession ];
5444
55- [self clearAppBadge ];
56- }
57-
58- - (void )applicationDidEnterBackground : (UIApplication *)application {
59- [[GTTracker sharedInstance ] endAnalyticsSession ];
60- }
45+ #pragma mark - Third-party library setup
6146
62- - (void )applicationWillTerminate : (UIApplication *)application {
63- [[GTTracker sharedInstance ] endAnalyticsSession ];
47+ - (void )setupThirdPartyLibraries {
48+ [ThemeManager setupTheme ];
49+ [Fabric with: @[CrashlyticsKit]];
50+ [[GTTracker sharedInstance ] initializeAnalyticsWithTrackingID: kAnalyticsTrackingID logLevel: kGAILogLevelError ];
6451}
6552
6653
@@ -75,42 +62,19 @@ - (void)application:(UIApplication *)application didRegisterUserNotificationSett
7562}
7663
7764- (void )application : (UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken : (NSData *)deviceToken {
78- NSString *token = [_dataManager tokenStringFromData: deviceToken];
65+ NSString *token = [[DataManager sharedInstance ] tokenStringFromData: deviceToken];
7966
8067 [[RequestManager sharedInstance ] sendDeviceToken: token completionHandler: ^(NSError *error) {
8168 if (error) {
8269 NSLog (@" Sending token to server failed with error: %@ " , error);
70+
71+ [[GTTracker sharedInstance ] sendAnalyticsEventWithCategory: @" Token Request Failed" action: error.localizedDescription];
8372 }
8473 }];
8574}
8675
8776- (void )application : (UIApplication *)application didReceiveRemoteNotification : (NSDictionary *)userInfo fetchCompletionHandler : (void (^)(UIBackgroundFetchResult))completionHandler {
88- [_dataManager performBackgroundFetchWithCompletionHandler: completionHandler];
77+ [[DataManager sharedInstance ] performBackgroundFetchWithCompletionHandler: completionHandler];
8978}
9079
91- - (void )clearAppBadge {
92- [UIApplication sharedApplication ].applicationIconBadgeNumber = 0 ;
93- }
94-
95-
96- #pragma mark - Analytics
97-
98- - (void )initializeAnalytics {
99- // Start up the GTTracker.
100- GTTracker *tracker = [GTTracker sharedInstance ];
101- tracker.loggingEnabled = NO ;
102- [tracker initializeAnalyticsWithTrackingID: kAnalyticsTrackingID logLevel: kGAILogLevelError ];
103- }
104-
105-
106- // TODO: Implement / test background fetch
107- //
108- // #pragma mark - Background fetch
109- //
110- // - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
111- // // Let the data manger handle the fetch.
112- // [[DataManager sharedInstance] performBackgroundFetchWithCompletionHandler:completionHandler];
113- // }
114-
115-
11680@end
0 commit comments