Skip to content

Commit cc02939

Browse files
committed
Clean up views after dismissing webview by swiping down
Current implementation cleans up views only when 'done' button is tapped. iOS 13 modal presentation style has other ways to dismiss view controllers than tapping 'done' button, so we need to add cleaning up code to them.
1 parent baf0a85 commit cc02939

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalWebView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#import <UIKit/UIKit.h>
2929
#import <WebKit/WebKit.h>
3030

31-
@interface OneSignalWebView : UIViewController <WKNavigationDelegate>
31+
@interface OneSignalWebView : UIViewController <WKNavigationDelegate, UIAdaptivePresentationControllerDelegate>
3232

3333
@property(nonatomic, copy)NSURL *url;
3434
@property(nonatomic)WKWebView *webView;

iOS_SDK/OneSignalSDK/Source/OneSignalWebView.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ - (void)viewDidAppear:(BOOL)animated {
6767

6868
- (void)dismiss:(id)sender {
6969
[self.navigationController dismissViewControllerAnimated:true completion:^{
70-
// Clear web view
71-
[_webView loadHTMLString:@"" baseURL:nil];
72-
if (viewControllerForPresentation)
73-
[viewControllerForPresentation.view removeFromSuperview];
70+
[self clearWebView];
7471
}];
7572
}
7673

@@ -108,6 +105,7 @@ - (void)showInApp {
108105
if (!navController) {
109106
navController = [[UINavigationController alloc] initWithRootViewController:self];
110107
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
108+
navController.presentationController.delegate = self;
111109
}
112110
if (!viewControllerForPresentation) {
113111
viewControllerForPresentation = [[UIViewController alloc] init];
@@ -133,7 +131,15 @@ - (void)showInApp {
133131
@catch(NSException* exception) { }
134132
}
135133

134+
- (void)clearWebView {
135+
[_webView loadHTMLString:@"" baseURL:nil];
136+
if (viewControllerForPresentation)
137+
[viewControllerForPresentation.view removeFromSuperview];
138+
}
136139

140+
- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController {
141+
[self clearWebView];
142+
}
137143

138144
@end
139145

0 commit comments

Comments
 (0)