diff --git a/example/ios/NotificationsExampleAppTests/RNNotificationsStoreTests.m b/example/ios/NotificationsExampleAppTests/RNNotificationsStoreTests.m index 951b5827c..1e3b15c9c 100644 --- a/example/ios/NotificationsExampleAppTests/RNNotificationsStoreTests.m +++ b/example/ios/NotificationsExampleAppTests/RNNotificationsStoreTests.m @@ -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"]); } diff --git a/lib/ios/RNNotificationsStore.m b/lib/ios/RNNotificationsStore.m index 880ddcd4d..bcc9abc85 100644 --- a/lib/ios/RNNotificationsStore.m +++ b/lib/ios/RNNotificationsStore.m @@ -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]; + }); } }