WKWebView takeSnapshot does not work on iOS 13

I need take screenshot of WebView while app in Background.

But on iOS13 method "takeSnapshotWithConfiguration:completionHandler:" of WKWebView does not work. completionHandler never fire when app does background task.

This works well on iOS12. Also it works on iOS13 while app in foreground.


Reproduce: see demo project to reproduce https://github.com/Jnis/WebView-Snapshot. Also see videos there.


Expected: takeSnapshotWithConfiguration:completionHandler call completionHandler with image while app is in background


Actual result:

[self.wkwebView takeSnapshotWithConfiguration:configuration completionHandler:^(UIImage * _Nullable snapshotImage, NSError * _Nullable error) {

// this never call on iOS13 while app in background. But iOS12 works well.

}];


Thank you!

Replies

Solution: setting WKSnapshotConfiguration’s afterScreenUpdates property to NO


WKSnapshotConfiguration *configuration = [WKSnapshotConfiguration new];
if (@available(iOS 13.0, *)) {
    configuration.afterScreenUpdates = NO;
}
Post not yet marked as solved Up vote reply of jnis Down vote reply of jnis
  • Thank you so much! I've been looking for a solution for this issue for ages and this was all I needed to do!

Add a Comment