Skip to content

Commit 5086507

Browse files
authored
don't execute operation block if it was canceled before (#429)
don't add prams if they are empty
1 parent 9df0746 commit 5086507

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Leanplum-SDK/Classes/Managers/Networking/LPRequest.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ - (NSMutableDictionary *)createArgsDictionary
110110
if ([LPAPIConfig sharedConfig].token) {
111111
args[LP_PARAM_TOKEN] = [LPAPIConfig sharedConfig].token;
112112
}
113-
[args addEntriesFromDictionary:self.params];
113+
if (self.params && self.params.count > 0) {
114+
[args addEntriesFromDictionary:self.params];
115+
}
114116

115117
// remove keys that are empty
116118
[args removeObjectForKey:@""];

Leanplum-SDK/Classes/Managers/Networking/LPRequestSender.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,16 @@ - (void)saveRequest:(LPRequest *)request
132132
RETURN_IF_TEST_MODE;
133133
if (!request.sent) {
134134
request.sent = YES;
135-
135+
136+
NSBlockOperation *saveRequestOperation = [NSBlockOperation new];
137+
__weak NSBlockOperation *weakOperation = saveRequestOperation;
138+
136139
void (^operationBlock)(void) = ^void() {
137140
LP_TRY
141+
if ([weakOperation isCancelled]) {
142+
return;
143+
}
144+
138145
NSString *uuid = [LPRequestUUIDHelper loadUUID];
139146
NSInteger count = [LPEventDataManager count];
140147
if (!uuid || count % LP_MAX_EVENTS_PER_API_CALL == 0) {
@@ -152,7 +159,8 @@ - (void)saveRequest:(LPRequest *)request
152159
LP_END_TRY
153160
};
154161

155-
[[LPOperationQueue serialQueue] addOperationWithBlock:operationBlock];
162+
[saveRequestOperation addExecutionBlock:operationBlock];
163+
[[LPOperationQueue serialQueue] addOperation:saveRequestOperation];
156164
}
157165

158166
[self.countAggregator incrementCount:@"send_eventually_lp"];

0 commit comments

Comments
 (0)