RMET-5110 ::: added fix do allow open url InAppBrowser and download a file - #46
OS-ruimoreiramendes wants to merge 1 commit into
Conversation
@OS-ruimoreiramendes Before it was already possible to navigate within the same web view right? |
@OS-ruimoreiramendes how does the same use case work in Android? Did the downloads already work? |
|
@OS-ruimoreiramendes if we're adding any new functionality, which I believe we might be, then we need to consider adding it on Android as well (if it doesn't already exist) |
|
@alexgerardojacinto as discussed on the call, since this PR introduces download functionality which was not previously supported (and would need to be considered for Android as well), I'll keep this PR open for future reference in case we decide to introduce this feature. |
| /// Indicates if a download is in progress, to suppress navigation errors caused by download redirects. | ||
| private var isDownloadInProgress: Bool = false | ||
| /// Retains the active WKDownload to prevent it from being deallocated mid-download. | ||
| private var activeDownload: AnyObject? |
There was a problem hiding this comment.
The way these variables are declared suggests that only one download can be in progress at a time. Is it guaranteed that multiple simultaneous downloads can never occur?
|
|
||
| func downloadDidFinish(_ download: WKDownload) { | ||
| guard let fileURL = downloadDestinationURL else { return } | ||
| activeDownload = nil |
There was a problem hiding this comment.
Should we update the isDownloadInProgress property here? Currently, it is only set to false when an error occurs.
| print("webView: \(delegateName) - \(error.localizedDescription)") | ||
| if (error as NSError).code != NSURLErrorCancelled { | ||
| let nsError = error as NSError | ||
| if isDownloadInProgress && nsError.code == 102 { |
There was a problem hiding this comment.
Could we replace the magic number 102 with a named constant or add a comment explaining its purpose?
| if FileManager.default.fileExists(atPath: fileURL.path) { | ||
| try? FileManager.default.removeItem(at: fileURL) | ||
| } | ||
| downloadDestinationURL = fileURL |
There was a problem hiding this comment.
Should we clean up the downloaded files at some point?
|
Hey @OS-ruimoreiramendes as the internal JIRA items have been discarded, we're closing this PR. |
Description
Handle
window.open()and file downloads inWKWebViewon iOSOn iOS,
WKWebViewsilently ignoreswindow.open()calls and cannot handle file download responses by default. This fix addresses both issues:window.open()to navigate within the same WebView, preserving the custom User AgentdecidePolicyFornavigationResponse to detect non-displayable MIME types and triggerWKDownload(iOS 14.5+), with aUIActivityViewControllerto allow the user to save or share the downloaded fileContext
Addresses: https://outsystemsrd.atlassian.net/browse/RMET-5110
Type of changes
Tests
Screenshots (if appropriate)
Checklist
RNMT-XXXX <title>