From a27b6eb41979aaf7206003c0cd0cb2f7ab0ed91c Mon Sep 17 00:00:00 2001 From: Maciej Banasiewicz Date: Mon, 29 Mar 2021 11:29:11 +0200 Subject: [PATCH 1/4] Add enableAutoplayWithSound flag to ANSDKSettings --- sdk/sourcefiles/ANSDKSettings.h | 5 +++ sdk/sourcefiles/internal/ANWebView.m | 38 ++++++------------- .../internal/config/ANSDKSettings.m | 1 + 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/sdk/sourcefiles/ANSDKSettings.h b/sdk/sourcefiles/ANSDKSettings.h index 29006e153..999de4663 100644 --- a/sdk/sourcefiles/ANSDKSettings.h +++ b/sdk/sourcefiles/ANSDKSettings.h @@ -37,6 +37,11 @@ */ @property (nonatomic, copy, nullable) BOOL (^shouldConstrainToSuperview)(NSValue* _Nonnull); +/** + If YES the SDK will enable auto playing videos with sound. Defaults to NO. + */ +@property (nonatomic) BOOL enableAutoplayWithSound; + /** * Set false to block Location popup asked by Creative, Also notify creative that User denied the request for location. * Set True continue the default behaviour. diff --git a/sdk/sourcefiles/internal/ANWebView.m b/sdk/sourcefiles/internal/ANWebView.m index 5509fc660..81341c230 100644 --- a/sdk/sourcefiles/internal/ANWebView.m +++ b/sdk/sourcefiles/internal/ANWebView.m @@ -155,36 +155,22 @@ + (void) addDefaultWebViewConfiguration configuration.processPool = anSdkProcessPool; configuration.allowsInlineMediaPlayback = YES; - - // configuration.allowsInlineMediaPlayback = YES is not respected - // on iPhone on WebKit versions shipped with iOS 9 and below, the - // video always loads in full-screen. - // See: https://bugs.webkit.org/show_bug.cgi?id=147512 - if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { - if (@available(iOS 10.0, *)) { - configuration.mediaTypesRequiringUserActionForPlayback = NO; - }else { - configuration.requiresUserActionForMediaPlayback = NO; - } - + + if (@available(iOS 10.0, *)) { + configuration.requiresUserActionForMediaPlayback = NO; + configuration.mediaTypesRequiringUserActionForPlayback = ANSDKSettings.sharedInstance.enableAutoplayWithSound ? WKAudiovisualMediaTypeNone : WKAudiovisualMediaTypeAudio; } else { - if ( [[NSProcessInfo processInfo] respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)] - && [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10,0,0}] ) - { - if (@available(iOS 10.0, *)) { - configuration.mediaTypesRequiringUserActionForPlayback = NO; - }else { - configuration.requiresUserActionForMediaPlayback = NO; - } + // configuration.allowsInlineMediaPlayback = YES is not respected + // on iPhone on WebKit versions shipped with iOS 9 and below, the + // video always loads in full-screen. + // See: https://bugs.webkit.org/show_bug.cgi?id=147512 + if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { + configuration.requiresUserActionForMediaPlayback = NO; } else { - if (@available(iOS 10.0, *)) { - configuration.mediaTypesRequiringUserActionForPlayback = YES; - }else { - configuration.requiresUserActionForMediaPlayback = YES; - } + configuration.requiresUserActionForMediaPlayback = YES; } } - + WKUserContentController *controller = [[WKUserContentController alloc] init]; configuration.userContentController = controller; diff --git a/sdk/sourcefiles/internal/config/ANSDKSettings.m b/sdk/sourcefiles/internal/config/ANSDKSettings.m index 7e1d6281a..f5ac66db2 100644 --- a/sdk/sourcefiles/internal/config/ANSDKSettings.m +++ b/sdk/sourcefiles/internal/config/ANSDKSettings.m @@ -105,6 +105,7 @@ + (id)sharedInstance { sdkSettings.auctionTimeout = 0; sdkSettings.nativeAdAboutToExpireInterval = kAppNexusNativeAdAboutToExpireInterval; sdkSettings.countImpressionOn1PxRendering = NO; + sdkSettings.enableAutoplayWithSound = NO; }); return sdkSettings; } From f356f210e15d12c3cfac7189161b09035060eba0 Mon Sep 17 00:00:00 2001 From: Maciej Banasiewicz Date: Fri, 9 Apr 2021 10:31:51 +0200 Subject: [PATCH 2/4] Update ANSDKSettings.h --- sdk/sourcefiles/ANSDKSettings.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sdk/sourcefiles/ANSDKSettings.h b/sdk/sourcefiles/ANSDKSettings.h index 999de4663..29006e153 100644 --- a/sdk/sourcefiles/ANSDKSettings.h +++ b/sdk/sourcefiles/ANSDKSettings.h @@ -37,11 +37,6 @@ */ @property (nonatomic, copy, nullable) BOOL (^shouldConstrainToSuperview)(NSValue* _Nonnull); -/** - If YES the SDK will enable auto playing videos with sound. Defaults to NO. - */ -@property (nonatomic) BOOL enableAutoplayWithSound; - /** * Set false to block Location popup asked by Creative, Also notify creative that User denied the request for location. * Set True continue the default behaviour. From 4e6091676fc1e13aa721a13a67280485bade267a Mon Sep 17 00:00:00 2001 From: Maciej Banasiewicz Date: Fri, 9 Apr 2021 10:32:21 +0200 Subject: [PATCH 3/4] Update ANSDKSettings.m --- sdk/sourcefiles/internal/config/ANSDKSettings.m | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/sourcefiles/internal/config/ANSDKSettings.m b/sdk/sourcefiles/internal/config/ANSDKSettings.m index f5ac66db2..7e1d6281a 100644 --- a/sdk/sourcefiles/internal/config/ANSDKSettings.m +++ b/sdk/sourcefiles/internal/config/ANSDKSettings.m @@ -105,7 +105,6 @@ + (id)sharedInstance { sdkSettings.auctionTimeout = 0; sdkSettings.nativeAdAboutToExpireInterval = kAppNexusNativeAdAboutToExpireInterval; sdkSettings.countImpressionOn1PxRendering = NO; - sdkSettings.enableAutoplayWithSound = NO; }); return sdkSettings; } From d72d73e06c14c5d5201aed104d14b34b1d81e1ed Mon Sep 17 00:00:00 2001 From: Maciej Banasiewicz Date: Fri, 9 Apr 2021 10:32:57 +0200 Subject: [PATCH 4/4] Update ANWebView.m --- sdk/sourcefiles/internal/ANWebView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/sourcefiles/internal/ANWebView.m b/sdk/sourcefiles/internal/ANWebView.m index 81341c230..885add8ac 100644 --- a/sdk/sourcefiles/internal/ANWebView.m +++ b/sdk/sourcefiles/internal/ANWebView.m @@ -158,7 +158,7 @@ + (void) addDefaultWebViewConfiguration if (@available(iOS 10.0, *)) { configuration.requiresUserActionForMediaPlayback = NO; - configuration.mediaTypesRequiringUserActionForPlayback = ANSDKSettings.sharedInstance.enableAutoplayWithSound ? WKAudiovisualMediaTypeNone : WKAudiovisualMediaTypeAudio; + configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAudio; } else { // configuration.allowsInlineMediaPlayback = YES is not respected // on iPhone on WebKit versions shipped with iOS 9 and below, the