user2259955
user2259955

Reputation: 1

Swift iOS Screenshot of entire Screen including Split View

I have been trying to figure out how to take a Screenshot / Screen Capture of not just the application view, but the complete screen of the device.

The main use case is around using the new multi-tasking features in iOS 9 and take a screen shot of the other app running.

Any help or guidance would be greatly appreciated.

let theView = view
var screenSize = UIScreen.mainScreen().bounds.size

if (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) && UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation) {
   screenSize = CGSizeMake(screenSize.height, screenSize.width)
}

UIGraphicsBeginImageContextWithOptions(screenSize, true, 0.0)

theView.drawViewHierarchyInRect(theView.bounds, afterScreenUpdates: true)

let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return image

Upvotes: 0

Views: 382

Answers (1)

rickster
rickster

Reputation: 126167

Press the Home and Sleep/wake buttons at the same time.

As for doing it programmatically, I think you're out of luck. Apps don't get access to the screen content drawn by other processes. This is presumably by design, as part of the security measures that keep apps out of each other's sandboxes.

Upvotes: 3

Related Questions