I've been looking for a long time around, i found some hints but i cannot figure out how to apply this to my problem. Would appreciate any help.
What trying to achieve is pretty straight forward:
My app includes a WKWebview playing a youtube video (with some overlaying text). I added a link to take a screenshot of the screen and to save it to the camera roll.
Result:
It works perfectly in Simulator but on device I can only see as a result overlaying text and background (supposed to be the video) is black.
Here is my current code (SWIFT 3):
...
// Save screenshot
UIImageWriteToSavedPhotosAlbum(captureScreen(), nil, nil, nil)
...
func captureScreen() -> UIImage {
UIGraphicsBeginImageContextWithOptions(webView!.bounds.size, webView!.isOpaque, 0)
webView!.drawHierarchy(in: webView!.bounds, afterScreenUpdates: false)
let image = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
I also tried (Same result)
...
UIImageWriteToSavedPhotosAlbum(captureScreen(), nil, nil, nil)
...
func captureScreen() -> UIImage {
let image = UIApplication.shared.screenShot!
return image
}
I've read online that we can't use renderInContext: because the GL layer containing the video player is not captured. So they suggest to actually merge content of UIImageView and EAGLview (link1, link2).
This sounds great but most of solutions i found are written in objective-c or relatively complex (link3, link4, link5).
I need help to find a solution in SWIFT.
Thank you in advance for your time.