File tree Expand file tree Collapse file tree 4 files changed +24
-10
lines changed Expand file tree Collapse file tree 4 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,6 @@ target 'Leanplum-SDK_Example' do
2020
2121 pod 'Leanplum-iOS-SDK' , :path => '../'
2222 pod 'OCMock' , '~> 3.3.1'
23- pod 'OHHTTPStubs'
23+ pod 'OHHTTPStubs' , '~> 9.0.0'
2424 end
2525end
Original file line number Diff line number Diff line change @@ -57,8 +57,13 @@ - (void)invokeResponseWithOperation:(id<LPNetworkOperationProtocol>)operation
5757
5858 // Ensure all callbacks are on main thread.
5959 if (![NSThread isMainThread ]) {
60+ // hold the reference to self until block is executed
61+ __strong __typeof__ (self) strongSelf = self;
6062 dispatch_async (dispatch_get_main_queue (), ^{
61- self.responseBlock (operation, response);
63+ __typeof__ (self) weakSelf = strongSelf;
64+ if (weakSelf) {
65+ weakSelf.responseBlock (operation, response);
66+ }
6267 });
6368 return ;
6469 }
@@ -74,8 +79,13 @@ - (void)invokeError:(NSError *)error
7479
7580 // Ensure all callbacks are on main thread.
7681 if (![NSThread isMainThread ]) {
82+ // hold the reference to self until block is executed
83+ __strong __typeof__ (self) strongSelf = self;
7784 dispatch_async (dispatch_get_main_queue (), ^{
78- self.errorBlock (error);
85+ __typeof__ (self) weakSelf = strongSelf;
86+ if (weakSelf) {
87+ weakSelf.errorBlock (error);
88+ }
7989 });
8090 return ;
8191 }
Original file line number Diff line number Diff line change @@ -82,13 +82,13 @@ + (void)invokeSuccessCallbacksOnResponses:(id)responses
8282
8383 // If index is in range, execute and remove it.
8484 // If not, requests are in the future. Update the index.
85- [callbackMap removeObjectForKey: indexObject];
8685 if (index >= requests.count ) {
8786 index -= requests.count ;
8887 updatedCallbackMap[@(index)] = eventCallback;
8988 } else if (eventCallback.responseBlock ) {
9089 activeResponseMap[indexObject] = [eventCallback.responseBlock copy ];
9190 }
91+ [callbackMap removeObjectForKey: indexObject];
9292 }
9393 [callbackMap addEntriesFromDictionary: updatedCallbackMap];
9494
Original file line number Diff line number Diff line change @@ -410,10 +410,12 @@ + (void)startWithUserId:(NSString *)userId userAttributes:(NSDictionary *)attrib
410410+ (void )triggerStartIssued
411411{
412412 [LPInternalState sharedState ].issuedStart = YES ;
413- for (LeanplumStartIssuedBlock block in [LPInternalState sharedState ].startIssuedBlocks .copy ) {
414- block ();
413+ @synchronized ([LPInternalState sharedState ].startIssuedBlocks ) {
414+ for (LeanplumStartIssuedBlock block in [LPInternalState sharedState ].startIssuedBlocks .copy ) {
415+ block ();
416+ }
417+ [[LPInternalState sharedState ].startIssuedBlocks removeAllObjects ];
415418 }
416- [[LPInternalState sharedState ].startIssuedBlocks removeAllObjects ];
417419}
418420
419421+ (void )triggerStartResponse : (BOOL )success
@@ -1274,10 +1276,12 @@ + (void)onStartIssued:(LeanplumStartIssuedBlock)block
12741276 if ([LPInternalState sharedState ].issuedStart ) {
12751277 block ();
12761278 } else {
1277- if (![LPInternalState sharedState ].startIssuedBlocks ) {
1278- [LPInternalState sharedState ].startIssuedBlocks = [NSMutableArray array ];
1279+ @synchronized ([LPInternalState sharedState ].startIssuedBlocks ) {
1280+ if (![LPInternalState sharedState ].startIssuedBlocks ) {
1281+ [LPInternalState sharedState ].startIssuedBlocks = [NSMutableArray array ];
1282+ }
1283+ [[LPInternalState sharedState ].startIssuedBlocks addObject: [block copy ]];
12791284 }
1280- [[LPInternalState sharedState ].startIssuedBlocks addObject: [block copy ]];
12811285 }
12821286}
12831287
You can’t perform that action at this time.
0 commit comments