Skip to content
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

Make compatible with iOS Extensions #54

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
348d975
Make compatible with iOS Extensions
andyyc Oct 14, 2015
6235a06
add ability to go offline
djih Oct 16, 2015
6a9ba3a
added tests for truncating events when offline
djih Oct 16, 2015
70c9c29
fix bug whewre fetching nil values from db causes crash
djih Oct 19, 2015
62b0f08
updated numEventsToRemove
djih Oct 20, 2015
9468fe2
v3.2.0
djih Oct 20, 2015
968ba0d
adding helper function to toggle trackingsessionevents
djih Oct 26, 2015
54b857d
switching fmdb header import
djih Oct 27, 2015
d1f0b93
remove helper function to toggle trackingSessionEvents
djih Oct 27, 2015
2c9b420
cleaning up tests
djih Oct 27, 2015
a3046da
add error handling around NSJSONSerialization during event data migra…
djih Nov 11, 2015
408314b
don't check session when sending session events
djih Nov 11, 2015
a29c61f
update readme
djih Nov 11, 2015
8301c27
update long to long long
djih Nov 12, 2015
03edfb3
v3.2.1
djih Nov 12, 2015
ead6dcf
add support for append
djih Dec 8, 2015
e7ca8a8
Readme updated
djmckee Dec 8, 2015
3d54095
expose updateLocation to public
djih Dec 9, 2015
4351f12
update readme
djih Dec 16, 2015
163ac67
v3.3.0
djih Dec 16, 2015
1283c71
removed fmdb dependency
djih Dec 17, 2015
0f5961b
change pods root to use srcroot
djih Dec 17, 2015
bde8b0d
fixed build, fixed tests
djih Dec 17, 2015
03487fb
undo changes to product bundle identifier
djih Dec 17, 2015
9c17f4d
add synchronous dispatch queue
djih Dec 18, 2015
864064d
finish switching to using dispatch queue
djih Dec 18, 2015
02bccdc
cleaning up build warnings
djih Dec 18, 2015
8cc7b2b
reverted ocmock and fixed tests
djih Dec 18, 2015
de8ecc1
updated changelog and podspec
djih Dec 19, 2015
b12ef66
cleanup and updated comments
djih Dec 19, 2015
05ff3a9
added inDatabase helper that prepares and finalizes statement
djih Dec 21, 2015
2d6fc05
don't need database object when working with statement
djih Dec 21, 2015
d5e7233
updated readme for using ios sdk without cocapods
djih Dec 21, 2015
b4a0f1b
update device platform add iphone 6s and ipod touch 6g
djih Dec 22, 2015
1452dd7
updated changelog
djih Dec 22, 2015
1ac62ff
updating readme
djih Dec 22, 2015
cb3a928
make json serializable before saving event to db
djih Dec 30, 2015
186f03b
update changelog
djih Dec 30, 2015
9348987
fix precision loss long long to integer
djih Dec 30, 2015
a308a7b
v3.4.0
djih Dec 30, 2015
0da0c18
guard db logging with debug flag
djih Dec 31, 2015
a020304
v3.4.1
djih Dec 31, 2015
47ee0df
fix framework search paths
djih Jan 6, 2016
7b88920
clear all operation
djih Jan 6, 2016
d65d20a
update readme
djih Jan 15, 2016
6359f7c
v3.5.0
djih Jan 15, 2016
395ac91
instanceWithName
djih Feb 3, 2016
bdd7f46
namespace plist, db file, separate dbhelper instances
djih Feb 5, 2016
3e8d1a5
add tests for separate instances
djih Feb 6, 2016
1233bdc
update readme and changelog
djih Feb 6, 2016
845ce1c
final cleanup
djih Feb 10, 2016
2b76ed5
fix tests
djih Feb 10, 2016
8d91943
remove amplitude partial mock, disable session tests
djih Feb 10, 2016
c9f3328
fix session tests
djih Feb 11, 2016
4021412
added comment on session test flakiness
djih Feb 11, 2016
6b23b0f
Correct the spelling of Xcode in README
ReadmeCritic Feb 16, 2016
89dfe9c
changed true/false to YES/NO
djih Feb 18, 2016
db06b77
Merge remote-tracking branch 'origin/master' into make_extension_comp…
andyyc Mar 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Amplitude.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
E98C05351A48E7FE00800C63 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
Expand All @@ -512,6 +513,7 @@
E98C05361A48E7FE00800C63 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
Expand Down
38 changes: 31 additions & 7 deletions Amplitude/Amplitude.m
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,16 @@ - (void)initializeApiKey:(NSString*) apiKey userId:(NSString*) userId setUserId:
}
}];

UIApplicationState state = [UIApplication sharedApplication].applicationState;
if (state != UIApplicationStateBackground) {
UIApplication * app = [self getSharedApplication];
if (app) {
UIApplicationState state = app.applicationState;
if (state != UIApplicationStateBackground) {
// If this is called while the app is running in the background, for example
// via a push notification, don't call enterForeground
[self enterForeground];
}
}

_initialized = YES;
}

Expand All @@ -485,6 +489,15 @@ - (BOOL)runOnBackgroundQueue:(void (^)(void))block
}
}

- (UIApplication *)getSharedApplication
{
Class UIApplicationClass = NSClassFromString(@"UIApplication");
if (UIApplicationClass && [UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
return [UIApplication performSelector:@selector(sharedApplication)];
}
return nil;
}

#pragma mark - logEvent

- (void)logEvent:(NSString*) eventType
Expand Down Expand Up @@ -961,7 +974,7 @@ - (void)makeEventUploadPostRequest:(NSString*) url events:(NSString*) events max
}

// Upload finished, allow background task to be ended
[[UIApplication sharedApplication] endBackgroundTask:_uploadTaskID];
[[self getSharedApplication] endBackgroundTask:_uploadTaskID];
_uploadTaskID = UIBackgroundTaskInvalid;
}
}];
Expand All @@ -971,13 +984,18 @@ - (void)makeEventUploadPostRequest:(NSString*) url events:(NSString*) events max

- (void)enterForeground
{
UIApplication *app = [self getSharedApplication];
if (!app) {
return;
}

[self updateLocation];

NSNumber* now = [NSNumber numberWithLongLong:[[self currentTime] timeIntervalSince1970] * 1000];

// Stop uploading
if (_uploadTaskID != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:_uploadTaskID];
[app endBackgroundTask:_uploadTaskID];
_uploadTaskID = UIBackgroundTaskInvalid;
}
[self runOnBackgroundQueue:^{
Expand All @@ -989,16 +1007,22 @@ - (void)enterForeground

- (void)enterBackground
{
UIApplication *app = [self getSharedApplication];
if (!app) {
return;
}

NSNumber* now = [NSNumber numberWithLongLong:[[self currentTime] timeIntervalSince1970] * 1000];

// Stop uploading
if (_uploadTaskID != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:_uploadTaskID];
[app endBackgroundTask:_uploadTaskID];
}
_uploadTaskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{

_uploadTaskID = [app beginBackgroundTaskWithExpirationHandler:^{
//Took too long, manually stop
if (_uploadTaskID != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:_uploadTaskID];
[app endBackgroundTask:_uploadTaskID];
_uploadTaskID = UIBackgroundTaskInvalid;
}
}];
Expand Down