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

finish run completion handler in main thread #748

Merged
merged 1 commit into from
Jun 23, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,28 @@ - (void)testSetPersentationCompletionHandler_ShouldStoreBlock {
}

- (void)testCompletePresentation_ShouldInvokeBlockWithParams {
XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
__block UNNotificationPresentationOptions presentationOptions;
void (^testBlock)(UNNotificationPresentationOptions) = ^void(UNNotificationPresentationOptions options) {
presentationOptions = options;
[expectation fulfill];
};
[_store setPresentationCompletionHandler:testBlock withCompletionKey:@"presentationTestBlock"];
[_store completePresentation:@"presentationTestBlock" withPresentationOptions:UNNotificationPresentationOptionAlert];
[self waitForExpectationsWithTimeout:1 handler:nil];
XCTAssertEqual(presentationOptions, UNNotificationPresentationOptionAlert);
}

- (void)testCompletePresentation_ShouldRemoveBlock {
XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
__block UNNotificationPresentationOptions presentationOptions;
void (^testBlock)(UNNotificationPresentationOptions) = ^void(UNNotificationPresentationOptions options) {
presentationOptions = options;
[expectation fulfill];
};
[_store setPresentationCompletionHandler:testBlock withCompletionKey:@"presentationTestBlock"];
[_store completePresentation:@"presentationTestBlock" withPresentationOptions:UNNotificationPresentationOptionAlert];
[self waitForExpectationsWithTimeout:1 handler:nil];
XCTAssertNil([_store getPresentationCompletionHandler:@"presentationTestBlock"]);
}

Expand Down
12 changes: 8 additions & 4 deletions lib/ios/RNNotificationsStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,20 @@ - (void)completeAction:(NSString *)completionKey {
- (void)completePresentation:(NSString *)completionKey withPresentationOptions:(UNNotificationPresentationOptions)presentationOptions {
void (^completionHandler)() = (void (^)(UNNotificationPresentationOptions))[_presentationCompletionHandlers valueForKey:completionKey];
if (completionHandler) {
completionHandler(presentationOptions);
[_presentationCompletionHandlers removeObjectForKey:completionKey];
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(presentationOptions);
[_presentationCompletionHandlers removeObjectForKey:completionKey];
});
}
}

- (void)completeBackgroundAction:(NSString *)completionKey withBackgroundFetchResult:(UIBackgroundFetchResult)backgroundFetchResult {
void (^completionHandler)() = (void (^)(UIBackgroundFetchResult))[_backgroundActionCompletionHandlers valueForKey:completionKey];
if (completionHandler) {
completionHandler(backgroundFetchResult);
[_backgroundActionCompletionHandlers removeObjectForKey:completionKey];
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(backgroundFetchResult);
[_backgroundActionCompletionHandlers removeObjectForKey:completionKey];
});
}
}

Expand Down