WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
245732
WKDownloadDelegate didFinish is called before download is written to file.
https://bugs.webkit.org/show_bug.cgi?id=245732
Summary
WKDownloadDelegate didFinish is called before download is written to file.
Garrigan Stafford
Reported
2022-09-27 08:02:18 PDT
When using a WKDownload to download a file, the download will succeed and calls -[WKDownloadDelegate downloadDidFinish:] before the download is actually written to file. Consider the following delegate method - (void)downloadDidFinish:(WKDownload *)download API_AVAILABLE(ios(15.0)) { BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:self.downloadPath.absoluteString]; UIAlertController* alertController = [UIAlertController alertControllerWithTitle:@"Download Succeeded" message:[NSString stringWithFormat:@Exists = %u", fileExists] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* dismiss = [UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:self.downloadPath.path]; NSLog(@"%u",fileExists); }]; [alertController addAction:dismiss]; if(NSThread.isMainThread) { [self.webViewController presentViewController:alertController animated:NO completion:nil]; } else { dispatch_async(dispatch_get_main_queue(), ^{ [self.webViewController presentViewController:alertController animated:NO completion:nil]; }); } } Upon a successful download the alert will be presented with "Exists = false" however once the dismiss is pressed we have logged "true". The file will exist after the call but not before. The delegate should be called AFTER the file has been created so that the delegate can respond to the file be downloaded.
Attachments
Sample Project
(70.74 KB, application/zip)
2022-09-29 13:46 PDT
,
Garrigan Stafford
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2022-09-29 09:26:24 PDT
<
rdar://problem/100566434
>
Alex Christensen
Comment 2
2022-09-29 12:52:34 PDT
This is curious. The file should exist and we have tests that verify that it does. I believe there may be an issue but I'll need more information, such as an example project. What is the size of the file? Is there anything interesting about the network conditions or the disk of the device?
Garrigan Stafford
Comment 3
2022-09-29 13:46:21 PDT
Created
attachment 462716
[details]
Sample Project
Garrigan Stafford
Comment 4
2022-09-29 13:48:46 PDT
Interesting. It has been behaving on iOS with the file not existing consistently. I have attached a sample project that when run on an iOS device will attempt to download a file and show whether or not it exists at the supplied path during and after the delegate call. As for download type and size, I have tested with a variety of sizes ranging form <1MB to ~25MB. I don't have the list immediately on me as it has been a while since testing. If i find it I will add to the comments.
Garrigan Stafford
Comment 5
2022-09-29 13:49:34 PDT
Also for the network conditions or disk there isn't anything that I would think of. it has reproduced on multiple models of iPhone and iPad and the networks are just normal home networks.
Garrigan Stafford
Comment 6
2023-05-31 09:12:38 PDT
Hey has there been any updates to this issue?
Garrigan Stafford
Comment 7
2023-10-17 10:16:39 PDT
Have y'all been able to reproduce with the sample project?
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug