I’ve written some code to download assets from a CDN. I’d like to be able to download them in chunks using the Range key. It all works great and as expected in the editor.
But on iOS, it seems to cache the initial request and will return the same information for all subsequent requests even though I’ve requested a different byte range.
The CONTENT-RANGE header value that is returned is always the initial chunk requested. To test this, I tried requesting chunks in the middle of the file instead of the beginning first by sending key:‘Range’ val:‘bytes=1024000-2047999’ and every request that has a different range of bytes still returns a CONTENT-RANGE of 1024000-2047999/12614176 even after uninstalling the application, then reinstalling. Even weirder is that whenever I try to download the same file without a byte range after doing this, it still only returns that chunk that I initially requested.
Here is some code to show you how I’m using WWW. You can assume the following code snippet is in a loop iterating over ranges of chunkSize until we have the entire file size. As stated earlier, all works as I intend it to in the edtior. Any help would be greatly appreciated. Thanks!
Dictionary< string, string > headers = new Dictionary< string, string >()
{
{ "Range", string.Format( "bytes={0}-{1}", startIndex, endIndex ) },
};
using( WWW www = new WWW( url, null, headers ) )
{
yield return www;
if( !string.IsNullOrEmpty( www.error ) )
{
yield break;
}
// Debug code
string contentRange = www.responseHeaders["CONTENT-RANGE"];
Debug.Log( "contentRange = " + contentRange + ", bytes = " + www.bytes.Length );
}