From e26f8766c985d289be2e4f1bf7ec3a0afeb7a5e9 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 7 Feb 2020 22:44:44 +0900 Subject: [PATCH] refactor: deprecate mediaPlaybackAllowsAirPlay Apple has deprecated "mediaPlaybackAllowsAirPlay" in iOS 8.0-9.0. This flag should be replaced with "allowsAirPlayForMediaPlayback". Preference name has also been changed to "AllowsAirPlayForMediaPlayback" --- .../Plugins/CDVWebViewEngine/CDVWebViewEngine.m | 10 +++++++++- tests/CordovaLibTests/CDVWebViewEngineTest.m | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m index 4c849b9e29..f4e47b3276 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m +++ b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m @@ -84,7 +84,15 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti configuration.mediaTypesRequiringUserActionForPlayback = mediaTypesRequiringUserActionForPlayback; configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO]; - configuration.mediaPlaybackAllowsAirPlay = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES]; + + // Check for usage of the older preference key, alert, and use. + BOOL allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowsAirPlayForMediaPlayback" defaultValue:YES]; + NSString *mediaPlaybackAllowsAirPlayKey = [settings cordovaSettingForKey:@"MediaPlaybackAllowsAirPlay"]; + if(mediaPlaybackAllowsAirPlayKey != nil) { + allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES]; + } + configuration.allowsAirPlayForMediaPlayback = allowsAirPlayForMediaPlayback; + return configuration; } diff --git a/tests/CordovaLibTests/CDVWebViewEngineTest.m b/tests/CordovaLibTests/CDVWebViewEngineTest.m index e21efc42fe..f91e8acbc5 100644 --- a/tests/CordovaLibTests/CDVWebViewEngineTest.m +++ b/tests/CordovaLibTests/CDVWebViewEngineTest.m @@ -92,7 +92,7 @@ - (void) testUpdateInfo { [@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO [@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @YES, // default is NO [@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO - [@"MediaPlaybackAllowsAirPlay" lowercaseString] : @NO, // default is YES + [@"AllowsAirPlayForMediaPlayback" lowercaseString] : @NO, // default is YES [@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO [@"WKWebViewDecelerationSpeed" lowercaseString] : @"fast" // default is 'normal' }; @@ -108,7 +108,7 @@ - (void) testUpdateInfo { XCTAssertTrue(wkWebView.configuration.mediaTypesRequiringUserActionForPlayback); XCTAssertFalse(wkWebView.configuration.allowsInlineMediaPlayback); XCTAssertFalse(wkWebView.configuration.suppressesIncrementalRendering); - XCTAssertTrue(wkWebView.configuration.mediaPlaybackAllowsAirPlay); + XCTAssertTrue(wkWebView.configuration.allowsAirPlayForMediaPlayback); // in the test above, DisallowOverscroll is YES, so no bounce if ([wkWebView respondsToSelector:@selector(scrollView)]) { @@ -135,7 +135,7 @@ - (void) testConfigurationFromSettings { [@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO [@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @YES, // default is NO [@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO - [@"MediaPlaybackAllowsAirPlay" lowercaseString] : @NO, // default is YES + [@"AllowsAirPlayForMediaPlayback" lowercaseString] : @NO, // default is YES [@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO [@"WKWebViewDecelerationSpeed" lowercaseString] : @"fast" // default is 'normal' }; @@ -157,7 +157,7 @@ - (void) testConfigurationFromSettings { XCTAssertTrue(wkWebView.configuration.allowsInlineMediaPlayback); XCTAssertTrue(wkWebView.configuration.suppressesIncrementalRendering); // The test case below is in a separate test "testConfigurationWithMediaPlaybackAllowsAirPlay" (Apple bug) - // XCTAssertFalse(wkWebView.configuration.mediaPlaybackAllowsAirPlay); + // XCTAssertFalse(wkWebView.configuration.allowsAirPlayForMediaPlayback); // in the test above, DisallowOverscroll is YES, so no bounce if ([wkWebView respondsToSelector:@selector(scrollView)]) {