From 96fe42440e42032acaf2fea9f06dba834d4a3aa8 Mon Sep 17 00:00:00 2001 From: Jens Andersson Date: Tue, 19 May 2020 17:34:55 +0200 Subject: [PATCH] Always set headers for iOS --- CHANGELOG.md | 1 + README.md | 2 -- ios/Video/RCTVideo.m | 11 ++++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 880b695c4f..c5be120476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added `preferredForwardBufferDuration` (iOS) - the duration the player should buffer media from the network ahead of the playhead to guard against playback disruption. (#1944) - Added `currentPlaybackTime` (Android ExoPlayer, iOS) - when playing an HLS live stream with a `EXT-X-PROGRAM-DATE-TIME` tag configured, then this property will contain the epoch value in msec. (#1944) - Added `trackId` (Android ExoPlayer) - Configure an identifier for the video stream to link the playback context to the events emitted. (#1944) +- Set iOS request headers without needing to edit RCTVideo.m. [#2014](https://github.com/react-native-community/react-native-video/pull/2014) ### Version 5.1.0-alpha5 diff --git a/README.md b/README.md index 9da556ebdb..0c8bd0056b 100644 --- a/README.md +++ b/README.md @@ -475,8 +475,6 @@ Platforms: iOS #### headers Pass headers to the HTTP client. Can be used for authorization. Headers must be a part of the source object. -To enable this on iOS, you will need to manually edit RCTVideo.m and uncomment the header code in the playerItemForSource function. This is because the code used a private API and may cause your app to be rejected by the App Store. Use at your own risk. - Example: ``` source={{ diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 8bfe702bd2..a24a33dedf 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -497,13 +497,10 @@ - (void)playerItemForSource:(NSDictionary *)source withCallback:(void(^)(AVPlaye NSMutableDictionary *assetOptions = [[NSMutableDictionary alloc] init]; if (isNetwork) { - /* Per #1091, this is not a public API. - * We need to either get approval from Apple to use this or use a different approach. - NSDictionary *headers = [source objectForKey:@"requestHeaders"]; - if ([headers count] > 0) { - [assetOptions setObject:headers forKey:@"AVURLAssetHTTPHeaderFieldsKey"]; - } - */ + NSDictionary *headers = [source objectForKey:@"requestHeaders"]; + if ([headers count] > 0) { + [assetOptions setObject:headers forKey:@"AVURLAssetHTTPHeaderFieldsKey"]; + } NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]; [assetOptions setObject:cookies forKey:AVURLAssetHTTPCookiesKey];