diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m index 186f4ff..d948d14 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m @@ -17,6 +17,7 @@ #import "MVMCoreErrorConstants.h" #import "MVMCoreLoggingHandler.h" #import "MVMCoreLoadingOverlayHandler.h" +#import "MVMCoreDispatchUtility.h" @interface MVMCoreNavigationHandler () @@ -275,27 +276,30 @@ #pragma mark - Presentation Extra - (void)presentViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated delegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock { - - UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [UIApplication sharedApplication].keyWindow.rootViewController; - if (!controllerToPresentOn) { - // Log if we are attempting to add an alert to nothing. - MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:nil message:@"The viewControllerToPresent on property is nil and an attempt was made to present." code:ErrorCodeNoViewControllerToPresentOn domain:ErrorDomainNative location:[NSString stringWithFormat:@"ViewController:%@|Delegate:%@",viewController.description,delegate]]; - [MVMCoreLoggingHandler addErrorToLog:error]; - } else { - MVMCorePresentViewControllerOperation *operation = [[MVMCorePresentViewControllerOperation alloc] initWithPresentingViewController:controllerToPresentOn presentedViewController:viewController animated:animated]; - operation.delegate = delegate; - operation.completionBlock = completionBlock; - [self.presentationQueue addOperation:operation]; - } + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [UIApplication sharedApplication].keyWindow.rootViewController; + if (!controllerToPresentOn) { + // Log if we are attempting to add an alert to nothing. + MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:nil message:@"The viewControllerToPresent on property is nil and an attempt was made to present." code:ErrorCodeNoViewControllerToPresentOn domain:ErrorDomainNative location:[NSString stringWithFormat:@"ViewController:%@|Delegate:%@",viewController.description,delegate]]; + [MVMCoreLoggingHandler addErrorToLog:error]; + } else { + MVMCorePresentViewControllerOperation *operation = [[MVMCorePresentViewControllerOperation alloc] initWithPresentingViewController:controllerToPresentOn presentedViewController:viewController animated:animated]; + operation.delegate = delegate; + operation.completionBlock = completionBlock; + [self.presentationQueue addOperation:operation]; + + } + }]; } - (void)dismissTopViewControllerAnimated:(BOOL)animated delegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock { - - // Dismiss on the main navigation controller. - UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [UIApplication sharedApplication].keyWindow.rootViewController; - MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissTopViewController:controllerToPresentOn animated:animated]; - operation.completionBlock = completionBlock; - [[NSOperationQueue mainQueue] addOperation:operation]; + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + // Dismiss on the main navigation controller. + UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [UIApplication sharedApplication].keyWindow.rootViewController; + MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissTopViewController:controllerToPresentOn animated:animated]; + operation.completionBlock = completionBlock; + [[NSOperationQueue mainQueue] addOperation:operation]; + }]; } - (void)dismissViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated delegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock { @@ -306,12 +310,13 @@ } - (void)dismissToBottom:(BOOL)animated delegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock { - - // Dismiss on the main navigation controller. - UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [UIApplication sharedApplication].keyWindow.rootViewController; - MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissViewController:controllerToPresentOn animated:animated]; - operation.completionBlock = completionBlock; - [[NSOperationQueue mainQueue] addOperation:operation]; + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + // Dismiss on the main navigation controller. + UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [UIApplication sharedApplication].keyWindow.rootViewController; + MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissViewController:controllerToPresentOn animated:animated]; + operation.completionBlock = completionBlock; + [[NSOperationQueue mainQueue] addOperation:operation]; + }]; } @end