[Webkit-unassigned] [Bug 245732] New: WKDownloadDelegate didFinish is called before download is written to file.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Sep 27 08:02:18 PDT 2022


https://bugs.webkit.org/show_bug.cgi?id=245732

            Bug ID: 245732
           Summary: WKDownloadDelegate didFinish is called before download
                    is written to file.
           Product: WebKit
           Version: Other
          Hardware: iPhone / iPad
                OS: All
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: WebKit API
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: gastaffo at microsoft.com

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.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20220927/a7cb9ea4/attachment-0001.htm>


More information about the webkit-unassigned mailing list