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

feat: Allow uploadInterval to be set manually #175

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 10 additions & 2 deletions Example/mParticleExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ - (NSArray *)cellTitles {

_cellTitles = @[@"Log Simple Event", @"Log Event", @"Log Screen", @"Log Commerce Event", @"Log Timed Event",
@"Log Error", @"Log Exception", @"Set User Attribute", @"Increment User Attribute",
@"Set Session Attribute", @"Increment Session Attribute", @"Register Remote", @"Log Base Event", @"Log Media Events", @"Toggle CCPA Consent", @"Toggle GDPR Consent", @"Request & Set IDFA", @"Logout", @"Login", @"Set IDFA"];
@"Set Session Attribute", @"Increment Session Attribute", @"Register Remote", @"Log Base Event", @"Log Media Events", @"Toggle CCPA Consent", @"Toggle GDPR Consent", @"Request & Set IDFA", @"Logout", @"Login", @"Set IDFA", @"Decrease Upload Timer", @"Increase Upload Timer"];

selectorNames = @[@"logSimpleEvent", @"logEvent", @"logScreen", @"logCommerceEvent", @"logTimedEvent",
@"logError", @"logException", @"setUserAttribute", @"incrementUserAttribute",
@"setSessionAttribute", @"incrementSessionAttribute", @"registerRemote", @"logBaseEvent", @"logCustomMediaEvents", @"toggleCCPAConsent", @"toggleGDPRConsent", @"requestIDFA", @"logout", @"login", @"modify"];
@"setSessionAttribute", @"incrementSessionAttribute", @"registerRemote", @"logBaseEvent", @"logCustomMediaEvents", @"toggleCCPAConsent", @"toggleGDPRConsent", @"requestIDFA", @"logout", @"login", @"modify", @"decreaseUploadInterval", @"increaseUploadInterval"];

return _cellTitles;
}
Expand Down Expand Up @@ -405,5 +405,13 @@ - (void)modify {
[self logIDFA:@"C56A4180-65AA-42EC-A945-5FD21DEC0538"];
}

-(void)decreaseUploadInterval {
[MParticle sharedInstance].uploadInterval = 1.0;
}

-(void)increaseUploadInterval {
[MParticle sharedInstance].uploadInterval = 1200.0;
}


@end
20 changes: 20 additions & 0 deletions UnitTests/MParticleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,26 @@ - (void)testUserAgentCustom {
[mockWebView stopMocking];
}

- (void)testUploadInterval {
MParticle *instance = [MParticle sharedInstance];
instance.backendController = [[MPBackendController alloc] init];

XCTAssertEqual(instance.uploadInterval, DEFAULT_DEBUG_UPLOAD_INTERVAL);
}

- (void)testSetUploadInterval {
MParticle *instance = [MParticle sharedInstance];
instance.backendController = [[MPBackendController alloc] init];
NSTimeInterval testInterval = 800.0;
instance.uploadInterval = testInterval;

#if TARGET_OS_TV == 1
XCTAssertEqual(instance.uploadInterval, DEFAULT_UPLOAD_INTERVAL);
#else
XCTAssertEqual(instance.uploadInterval, testInterval);
#endif
}

#pragma mark Error, Exception, and Crash Handling Tests

- (void)testLogCrash {
Expand Down
5 changes: 3 additions & 2 deletions mParticle-Apple-SDK/Include/mParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,10 @@ Defaults to false. Prevents the eventsHost above from overwriting the alias endp
Gets/Sets the interval to upload data to mParticle servers.

Batches of data are sent periodically to the mParticle servers at the rate defined by the uploadInterval. Batches are also uploaded
when the application is sent to the background or before they are terminated.
when the application is sent to the background or before they are terminated. When set, an upload is performed immediately before the sdk adheres to the new upload interval.
The minimum uploadInterval is 1 second (1.0). The default uploadInterval is 10 minutes (600.0) on iOS and 6 seconds (6.0) on tvOS.
*/
@property (nonatomic, readonly) NSTimeInterval uploadInterval;
@property (nonatomic, readwrite) NSTimeInterval uploadInterval;

/**
mParticle Apple SDK version
Expand Down
7 changes: 7 additions & 0 deletions mParticle-Apple-SDK/mParticle.m
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ - (NSString *)uniqueIdentifier {
return [MParticle sharedInstance].stateMachine.consumerInfo.uniqueIdentifier;
}

- (void)setUploadInterval:(NSTimeInterval)uploadInterval {
if (uploadInterval >= 1.0 && uploadInterval != self.backendController.uploadInterval) {
[self upload];
self.backendController.uploadInterval = uploadInterval;
}
}

- (NSTimeInterval)uploadInterval {
return self.backendController.uploadInterval;
}
Expand Down