1

I am using WKURLSchemeHandler to serve local files that cannot be read directly by the WkWebView. While it works fine for small files like videos, it totally freezes the application when it has to provide big files like videos.

Right now, I am reading the full file in a single step which is inappropriate for important files.

data = try Data(contentsOf: fileUrl)

How should I do in order to avoid this? Is there a way to "stream" the content of the file?

asked Oct 3, 2019 at 10:50

1 Answer 1

1

didReceive(Data) is special and can be called multiple times with partial data, so chunked reading/streaming is possible. It's not obvious from the docs, but they said so at their presentation uf the scheme handler feature (see 32:30): https://developer.apple.com/videos/play/wwdc2017/220/

Furthermore, WKURLSchemeTask's functions can be called on a background thread, no need to do it on the main thread (and potentially blocking the UI).

answered Oct 1, 2020 at 21:20
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your answer. Are you aware of any sample code showing how to stream data in the response?
@RichardLovejoy There is another SO question that has a sample implementation: stackoverflow.com/questions/69216563/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.