-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement app-lifecycle groundwork #2800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7eb873
Create the lifecycle class
mikehaney24 aa7f750
Add running in background properties and implement archive paths for …
mikehaney24 faeb3be
Move -stopTimer into the upload coordinator
mikehaney24 3c5a4c1
Add test for encoding and decoding the storage singleton.
mikehaney24 f81aa72
Add a test transport target.
mikehaney24 de2c503
Style
mikehaney24 6a2fb56
Temporarily commenting out sending lifecycle events.
mikehaney24 bcbb563
More style.
mikehaney24 c4d0f6d
Demonstrate that I know what year I made this file
mikehaney24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
GoogleDataTransport/GoogleDataTransport/Classes/GDTLifecycle.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2019 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import "GDTLifecycle.h" | ||
|
||
#import <GoogleDataTransport/GDTEvent.h> | ||
|
||
#import "GDTRegistrar_Private.h" | ||
#import "GDTStorage_Private.h" | ||
#import "GDTTransformer_Private.h" | ||
#import "GDTUploadCoordinator_Private.h" | ||
|
||
@implementation GDTLifecycle | ||
|
||
+ (void)load { | ||
[self sharedInstance]; | ||
} | ||
|
||
/** Creates/returns the singleton instance of this class. | ||
* | ||
* @return The singleton instance of this class. | ||
*/ | ||
+ (instancetype)sharedInstance { | ||
static GDTLifecycle *sharedInstance; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
sharedInstance = [[GDTLifecycle alloc] init]; | ||
}); | ||
return sharedInstance; | ||
} | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
if (self) { | ||
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; | ||
[notificationCenter addObserver:self | ||
selector:@selector(applicationDidEnterBackground:) | ||
name:UIApplicationDidEnterBackgroundNotification | ||
object:nil]; | ||
[notificationCenter addObserver:self | ||
selector:@selector(applicationWillEnterForeground:) | ||
name:UIApplicationWillEnterForegroundNotification | ||
object:nil]; | ||
|
||
NSString *name = UIApplicationWillTerminateNotification; | ||
[notificationCenter addObserver:self | ||
selector:@selector(applicationWillTerminate:) | ||
name:name | ||
object:nil]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
} | ||
|
||
- (void)applicationDidEnterBackground:(NSNotification *)notification { | ||
// UIApplication *application = [UIApplication sharedApplication]; | ||
// [[GDTTransformer sharedInstance] appWillBackground:application]; | ||
// [[GDTStorage sharedInstance] appWillBackground:application]; | ||
// [[GDTUploadCoordinator sharedInstance] appWillBackground:application]; | ||
// [[GDTRegistrar sharedInstance] appWillBackground:application]; | ||
} | ||
|
||
- (void)applicationWillEnterForeground:(NSNotification *)notification { | ||
// UIApplication *application = [UIApplication sharedApplication]; | ||
// [[GDTTransformer sharedInstance] appWillForeground:application]; | ||
// [[GDTStorage sharedInstance] appWillForeground:application]; | ||
// [[GDTUploadCoordinator sharedInstance] appWillForeground:application]; | ||
// [[GDTRegistrar sharedInstance] appWillForeground:application]; | ||
} | ||
|
||
- (void)applicationWillTerminate:(NSNotification *)notification { | ||
// UIApplication *application = [UIApplication sharedApplication]; | ||
// [[GDTTransformer sharedInstance] appWillTerminate:application]; | ||
// [[GDTStorage sharedInstance] appWillTerminate:application]; | ||
// [[GDTUploadCoordinator sharedInstance] appWillTerminate:application]; | ||
// [[GDTRegistrar sharedInstance] appWillTerminate:application]; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
GoogleDataTransport/GoogleDataTransport/Classes/Public/GDTLifecycle.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <UIKit/UIKit.h> | ||
|
||
@class GDTEvent; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** A protocol defining the lifecycle events objects in the library must respond to immediately. */ | ||
@protocol GDTLifecycleProtocol <NSObject> | ||
|
||
@required | ||
|
||
/** Indicates an imminent app termination in the rare occurrence when -applicationWillTerminate: has | ||
* been called. | ||
* | ||
* @param app The UIApplication instance. | ||
*/ | ||
- (void)appWillTerminate:(UIApplication *)app; | ||
|
||
/** Indicates that the app is moving to background and eventual suspension. | ||
* | ||
* @param app The UIApplication instance. | ||
*/ | ||
- (void)appWillBackground:(UIApplication *)app; | ||
|
||
/** Indicates that the app is resuming operation. | ||
* | ||
* @param app The UIApplication instance. | ||
*/ | ||
- (void)appWillForeground:(UIApplication *)app; | ||
|
||
@end | ||
|
||
/** This class manages the library's response to app lifecycle events. | ||
* | ||
* When backgrounding, the library doesn't stop processing events, it's just that several background | ||
* tasks will end up being created for every event that's sent, and the stateful objects of the | ||
* library (GDTStorage and GDTUploadCoordinator singletons) will deserialize themselves from and to | ||
* disk before and after every operation, respectively. | ||
*/ | ||
@interface GDTLifecycle : NSObject <UIApplicationDelegate> | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.