@@ -617,7 +617,11 @@ - (void)showPopup
617617 BOOL isPushAskToAsk = [context.actionName isEqualToString: LPMT_PUSH_ASK_TO_ASK];
618618
619619 if (isWeb) {
620- _popupView = [[UIWebView alloc ] init ];
620+ WKWebViewConfiguration * configuration = [WKWebViewConfiguration new ];
621+ configuration.allowsInlineMediaPlayback = YES ;
622+ configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone ;
623+
624+ _popupView = [[WKWebView alloc ] initWithFrame: CGRectZero configuration: configuration];
621625 } else {
622626 _popupView = [[UIView alloc ] init ];
623627 }
@@ -627,8 +631,8 @@ - (void)showPopup
627631 if ([context.actionName isEqualToString: LPMT_HTML_NAME]) {
628632 _popupView.backgroundColor = [UIColor clearColor ];
629633 [_popupView setOpaque: NO ];
630- ((UIWebView *)_popupView).scrollView .scrollEnabled = NO ;
631- ((UIWebView *)_popupView).scrollView .bounces = NO ;
634+ ((WKWebView *)_popupView).scrollView .scrollEnabled = NO ;
635+ ((WKWebView *)_popupView).scrollView .bounces = NO ;
632636 }
633637
634638 if (!isWeb) {
@@ -758,7 +762,7 @@ - (void)closePopupWithAnimation:(BOOL)animated
758762 }
759763
760764 // UI can't be modified in background.
761- if (![NSThread isMainThread ]) {
765+ if (![NSThread isMainThread ]) {
762766 dispatch_sync (dispatch_get_main_queue (), ^{
763767 [self closePopupWithAnimation: animated actionNamed: actionName track: track];
764768 });
@@ -770,8 +774,8 @@ - (void)closePopupWithAnimation:(BOOL)animated
770774
771775 if ([[context actionName ] isEqualToString: LPMT_WEB_INTERSTITIAL_NAME] ||
772776 [[context actionName ] isEqualToString: LPMT_HTML_NAME] ) {
773- ((UIWebView *)_popupView).delegate = nil ;
774- [(UIWebView *)_popupView stopLoading ];
777+ ((WKWebView *)_popupView).navigationDelegate = nil ;
778+ [(WKWebView *)_popupView stopLoading ];
775779 }
776780
777781 void (^finishCallback)(void ) = ^() {
@@ -1205,18 +1209,16 @@ - (void)refreshPopupContent
12051209 [actionName isEqualToString: LPMT_HTML_NAME]) {
12061210 if (_popupGroup) {
12071211 [_popupGroup setHidden: YES ]; // Keep hidden until load is done
1208- UIWebView *webView = (UIWebView *)_popupView;
1212+ WKWebView *webView = (WKWebView *)_popupView;
12091213 _webViewNeedsFade = YES ;
1210- webView.delegate = self;
1214+ webView.navigationDelegate = self;
12111215 if (@available (iOS 11.0 , *)) {
12121216 webView.scrollView .contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
12131217 }
12141218 if ([actionName isEqualToString: LPMT_WEB_INTERSTITIAL_NAME]) {
12151219 [webView loadRequest: [NSURLRequest requestWithURL:
12161220 [NSURL URLWithString: [context stringNamed: LPMT_ARG_URL]]]];
12171221 } else {
1218- webView.allowsInlineMediaPlayback = YES ;
1219- webView.mediaPlaybackRequiresUserAction = NO ;
12201222 NSString *html = [context htmlWithTemplateNamed: LPMT_ARG_HTML_TEMPLATE];
12211223 [webView loadHTMLString: html baseURL: nil ];
12221224 }
@@ -1315,9 +1317,9 @@ - (void)setAlternateIconWithFilename:(NSString *)filename
13151317 }
13161318}
13171319
1318- #pragma mark - UIWebViewDelegate methods
1320+ #pragma mark - WKWebViewDelegate methods
13191321
1320- - (void )showWebview : (UIWebView *)webview {
1322+ - (void )showWebview : (WKWebView *)webview {
13211323 [_popupGroup setHidden: NO ];
13221324 if (_webViewNeedsFade) {
13231325 _webViewNeedsFade = NO ;
@@ -1345,7 +1347,7 @@ - (NSDictionary *)queryComponentsFromUrl:(NSString *)url {
13451347 return components;
13461348}
13471349
1348- - (void )webViewDidFinishLoad : (UIWebView *)webView
1350+ - (void )webView : ( WKWebView *)webView didFinishNavigation : ( WKNavigation *) navigation
13491351{
13501352 if (webView.isLoading ) {
13511353 return ;
@@ -1358,29 +1360,32 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
13581360 }
13591361}
13601362
1361- - (BOOL )webView : (UIWebView *)webView shouldStartLoadWithRequest : (NSURLRequest *)request
1362- navigationType : (UIWebViewNavigationType)navigationType
1363+ - (void )webView : (WKWebView *)webView decidePolicyForNavigationAction : (WKNavigationAction *)navigationAction decisionHandler : (void (^)(WKNavigationActionPolicy ))decisionHandler
13631364{
13641365 LPActionContext *context = _contexts.lastObject ;
13651366 @try {
1366- NSString *url = request.URL .absoluteString ;
1367+
1368+ NSString *url = [navigationAction request ].URL .absoluteString ;
13671369 NSDictionary *queryComponents = [self queryComponentsFromUrl: url];
13681370 if ([url rangeOfString: [context stringNamed: LPMT_ARG_URL_CLOSE]].location != NSNotFound ) {
13691371 [self dismiss ];
13701372 if (queryComponents[@" result" ]) {
13711373 [Leanplum track: queryComponents[@" result" ]];
13721374 }
1373- return NO ;
1375+ decisionHandler (WKNavigationActionPolicyCancel );
1376+ return ;
13741377 }
13751378
13761379 // Only continue for HTML Template. Web Insterstitial will be deprecated.
13771380 if ([[context actionName ] isEqualToString: LPMT_WEB_INTERSTITIAL_NAME]) {
1378- return YES ;
1381+ decisionHandler (WKNavigationActionPolicyAllow );
1382+ return ;
13791383 }
13801384
13811385 if ([url rangeOfString: [context stringNamed: LPMT_ARG_URL_OPEN]].location != NSNotFound ) {
13821386 [self showWebview: webView];
1383- return NO ;
1387+ decisionHandler (WKNavigationActionPolicyCancel );
1388+ return ;
13841389 }
13851390
13861391 if ([url rangeOfString: [context stringNamed: LPMT_ARG_URL_TRACK]].location != NSNotFound ) {
@@ -1399,28 +1404,31 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
13991404 [Leanplum track: event withValue: value andInfo: info andParameters: parameters];
14001405 }
14011406 }
1402- return NO ;
1407+ decisionHandler (WKNavigationActionPolicyCancel );
1408+ return ;
14031409 }
14041410
14051411 if ([url rangeOfString: [context stringNamed: LPMT_ARG_URL_ACTION]].location != NSNotFound ) {
14061412 if (queryComponents[@" action" ]) {
14071413 [self closePopupWithAnimation: YES actionNamed: queryComponents[@" action" ] track: NO ];
14081414 }
1409- return NO ;
1415+ decisionHandler (WKNavigationActionPolicyCancel );
1416+ return ;
14101417 }
14111418
14121419 if ([url rangeOfString:
14131420 [context stringNamed: LPMT_ARG_URL_TRACK_ACTION]].location != NSNotFound ) {
14141421 if (queryComponents[@" action" ]) {
14151422 [self closePopupWithAnimation: YES actionNamed: queryComponents[@" action" ] track: YES ];
14161423 }
1417- return NO ;
1424+ decisionHandler (WKNavigationActionPolicyCancel );
1425+ return ;
14181426 }
14191427 }
14201428 @catch (NSException *exception) {
14211429 LOG_LP_MESSAGE_EXCEPTION;
14221430 }
1423- return YES ;
1431+ decisionHandler ( WKNavigationActionPolicyAllow ) ;
14241432}
14251433
14261434/* *
0 commit comments