Skip to content

Commit

Permalink
refactor: deprecate mediaPlaybackAllowsAirPlay
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
erisu committed Feb 22, 2020
1 parent 4ac1552 commit 60795b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti
configuration.mediaTypesRequiringUserActionForPlayback = mediaTypesRequiringUserActionForPlayback;

configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO];
configuration.mediaPlaybackAllowsAirPlay = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];

/*
* If the old preference key "MediaPlaybackAllowsAirPlay" exists, use it or default to "YES".
* Check if the new preference key "AllowsAirPlayForMediaPlayback" exists and overwrite the "MediaPlaybackAllowsAirPlay" value.
*/
BOOL allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];
if([settings cordovaSettingForKey:@"AllowsAirPlayForMediaPlayback"] != nil) {
allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];
}
configuration.allowsAirPlayForMediaPlayback = allowsAirPlayForMediaPlayback;

return configuration;
}

Expand Down
3 changes: 2 additions & 1 deletion bin/templates/scripts/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ function updateFileResources (cordovaProject, locations) {

function alertDeprecatedPreference (configParser) {
const deprecatedToNewPreferences = {
MediaPlaybackRequiresUserAction: 'MediaTypesRequiringUserActionForPlayback'
MediaPlaybackRequiresUserAction: 'MediaTypesRequiringUserActionForPlayback',
MediaPlaybackAllowsAirPlay: 'AllowsAirPlayForMediaPlayback'
};

Object.keys(deprecatedToNewPreferences).forEach(oldKey => {
Expand Down
8 changes: 4 additions & 4 deletions tests/CordovaLibTests/CDVWebViewEngineTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
Expand All @@ -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)]) {
Expand All @@ -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'
};
Expand All @@ -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)]) {
Expand Down

0 comments on commit 60795b6

Please sign in to comment.