From 4e2b610a829f6fe80660c811b52f600cd20f3ec0 Mon Sep 17 00:00:00 2001 From: Grigorii Lutkov Date: Sat, 7 Sep 2024 00:27:48 +0300 Subject: [PATCH] Try to fix crash #62 fix: add weakself reference to try to avoid crash (#92) Closes #62 --- LGAlertView/LGAlertViewController.m | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/LGAlertView/LGAlertViewController.m b/LGAlertView/LGAlertViewController.m index 23bbf2b..afa6ea3 100644 --- a/LGAlertView/LGAlertViewController.m +++ b/LGAlertView/LGAlertViewController.m @@ -54,10 +54,22 @@ - (nonnull instancetype)initWithAlertView:(nonnull LGAlertView *)alertView view: - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + __weak typeof(self) weakSelf = self; + __weak typeof(coordinator) weakCoordinator = coordinator; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [UIView animateWithDuration:coordinator.transitionDuration animations:^{ - [self setNeedsStatusBarAppearanceUpdate]; - [self.alertView layoutValidateWithSize:size]; + if (!weakSelf) { + return; + } + __strong typeof(weakSelf) strongSelf = weakSelf; + float transitionDuration = ^{ + if (weakCoordinator) { + return weakCoordinator.transitionDuration; + } + return [[LGAlertView appearance] animationDuration]; + }(); + [UIView animateWithDuration:transitionDuration animations:^{ + [strongSelf setNeedsStatusBarAppearanceUpdate]; + [strongSelf.alertView layoutValidateWithSize:size]; }]; }); }