Skip to content

Commit

Permalink
action completeHandler must run on main thread (#692)
Browse files Browse the repository at this point in the history
On iOS 14 built with Xcode 12 fixes a crash mentioning that completionHandler should run on the main thread

Co-authored-by: yogevbd <[email protected]>
  • Loading branch information
enahum and yogevbd authored Oct 28, 2020
1 parent f33acb6 commit d9433c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ - (void)testSetActionCompletionHandler_ShouldStoreBlock {
}

- (void)testCompleteAction_ShouldInvokeBlock {
__block BOOL blockInvoked = NO;
XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
void (^testBlock)(void) = ^void() {
blockInvoked = YES;
[expectation fulfill];
};
[_store setActionCompletionHandler:testBlock withCompletionKey:@"actionTestBlock"];
[_store completeAction:@"actionTestBlock"];
XCTAssertTrue(blockInvoked);
[self waitForExpectationsWithTimeout:1 handler:nil];
}

- (void)testCompleteAction_ShouldRemoveBlock {
__block BOOL blockInvoked = NO;
XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
void (^testBlock)(void) = ^void() {
blockInvoked = YES;
[expectation fulfill];
};
[_store setActionCompletionHandler:testBlock withCompletionKey:@"actionTestBlock"];
[_store completeAction:@"actionTestBlock"];
XCTAssertNil([_store getActionCompletionHandler:@"actionTestBlock"]);
[self waitForExpectationsWithTimeout:1 handler:nil];
}


Expand Down
6 changes: 4 additions & 2 deletions lib/ios/RNNotificationsStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ - (void)setBackgroundActionCompletionHandler:(void (^)(UIBackgroundFetchResult))
- (void)completeAction:(NSString *)completionKey {
void (^completionHandler)() = (void (^)())[_actionCompletionHandlers valueForKey:completionKey];
if (completionHandler) {
completionHandler();
[_actionCompletionHandlers removeObjectForKey:completionKey];
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler();
[_actionCompletionHandlers removeObjectForKey:completionKey];
});
}
}

Expand Down

0 comments on commit d9433c7

Please sign in to comment.