From cbd526d318fc6c62cbebb1d8c89a2a7a6f7f76d8 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Wed, 30 Oct 2019 16:30:13 +0100 Subject: [PATCH] fix(ios): mitigate media memory usage (#459) --- src/ios/IONAssetHandler.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ios/IONAssetHandler.m b/src/ios/IONAssetHandler.m index 52135fa3..5ed1f0f8 100644 --- a/src/ios/IONAssetHandler.m +++ b/src/ios/IONAssetHandler.m @@ -36,8 +36,14 @@ - (void)webView:(WKWebView *)webView startURLSchemeTask:(id )ur } } } - - NSData * data = [[NSData alloc] initWithContentsOfFile:startPath]; + NSError * fileError = nil; + NSData * data = nil; + if ([self isMediaExtension:url.pathExtension]) { + data = [NSData dataWithContentsOfFile:startPath options:NSDataReadingMappedIfSafe error:&fileError]; + } + if (!data || fileError) { + data = [[NSData alloc] initWithContentsOfFile:startPath]; + } NSInteger statusCode = 200; if (!data) { statusCode = 404;