Skip to content

Commit

Permalink
mitigates potential dismiss button related crashes for inapps
Browse files Browse the repository at this point in the history
  • Loading branch information
Akash Malhotra committed Apr 2, 2024
1 parent 94db7cf commit ee52f07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
20 changes: 12 additions & 8 deletions CleverTapSDK/CTInAppDisplayViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,26 @@ - (void)showFromWindow:(BOOL)animated {
}

- (void)hideFromWindow:(BOOL)animated {
void (^completionBlock)(void) = ^ {
[self.window removeFromSuperview];
self.window = nil;
if (self.delegate && [self.delegate respondsToSelector:@selector(notificationDidDismiss:fromViewController:)]) {
[self.delegate notificationDidDismiss:self.notification fromViewController:self];
__weak typeof(self) weakSelf = self;
void (^completionBlock)(void) = ^{
typeof(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
[strongSelf.window removeFromSuperview];
strongSelf.window = nil;
if (strongSelf.delegate && [strongSelf.delegate respondsToSelector:@selector(notificationDidDismiss:fromViewController:)]) {
[strongSelf.delegate notificationDidDismiss:strongSelf.notification fromViewController:strongSelf];
}
};

if (animated) {
[UIView animateWithDuration:0.25 animations:^{
self.window.alpha = 0;
weakSelf.window.alpha = 0;
} completion:^(BOOL finished) {
completionBlock();
}];
}
else {
} else {
completionBlock();
}
}
Expand Down
22 changes: 0 additions & 22 deletions CleverTapSDK/InApps/CTInAppHTMLViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -520,28 +520,6 @@ - (void)showFromWindow:(BOOL)animated {
}
}

- (void)hideFromWindow:(BOOL)animated {
void (^completionBlock)(void) = ^ {
[self.window removeFromSuperview];
self.window = nil;
if (self.delegate && [self.delegate respondsToSelector:@selector(notificationDidDismiss:fromViewController:)]) {
[self.delegate notificationDidDismiss:self.notification fromViewController:self];
}
};

if (animated) {
[UIView animateWithDuration:0.25 animations:^{
self.window.alpha = 0;
} completion:^(BOOL finished) {
completionBlock();
}];
}
else {
completionBlock();
}
}


#pragma mark - Public

- (void)show:(BOOL)animated {
Expand Down

0 comments on commit ee52f07

Please sign in to comment.