Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Commonmark migration
Source Link

#Swift, iOS 13:

Swift, iOS 13:

The code below (and other ways of accessing) will now crash the app with a message:

App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.

The window scenes and statusBarManager's really only give us access to frame - if this is still possible, I am not aware how.

#Swift, iOS10-12:

Swift, iOS10-12:

The following works for me, and after profiling all the methods for capturing programmatic screenshots - this is the quickest, and the recommended way from Apple following iOS 10

let screenshotSize = CGSize(width: UIScreen.main.bounds.width * 0.6, height: UIScreen.main.bounds.height * 0.6) let renderer = UIGraphicsImageRenderer(size: screenshotSize) let statusBar = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow let screenshot = renderer.image { _ in UIApplication.shared.keyWindow?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) statusBar?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) } 

You don't have to scale your screenshot size down (you can use UIScreen.main.bounds directly if you want)

#Swift, iOS 13:

The code below (and other ways of accessing) will now crash the app with a message:

App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.

The window scenes and statusBarManager's really only give us access to frame - if this is still possible, I am not aware how.

#Swift, iOS10-12:

The following works for me, and after profiling all the methods for capturing programmatic screenshots - this is the quickest, and the recommended way from Apple following iOS 10

let screenshotSize = CGSize(width: UIScreen.main.bounds.width * 0.6, height: UIScreen.main.bounds.height * 0.6) let renderer = UIGraphicsImageRenderer(size: screenshotSize) let statusBar = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow let screenshot = renderer.image { _ in UIApplication.shared.keyWindow?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) statusBar?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) } 

You don't have to scale your screenshot size down (you can use UIScreen.main.bounds directly if you want)

Swift, iOS 13:

The code below (and other ways of accessing) will now crash the app with a message:

App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.

The window scenes and statusBarManager's really only give us access to frame - if this is still possible, I am not aware how.

Swift, iOS10-12:

The following works for me, and after profiling all the methods for capturing programmatic screenshots - this is the quickest, and the recommended way from Apple following iOS 10

let screenshotSize = CGSize(width: UIScreen.main.bounds.width * 0.6, height: UIScreen.main.bounds.height * 0.6) let renderer = UIGraphicsImageRenderer(size: screenshotSize) let statusBar = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow let screenshot = renderer.image { _ in UIApplication.shared.keyWindow?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) statusBar?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) } 

You don't have to scale your screenshot size down (you can use UIScreen.main.bounds directly if you want)

added 445 characters in body
Source Link
gadu
  • 1.8k
  • 1
  • 18
  • 32

#Swift, iOS10+iOS 13:

The code below (and other ways of accessing) will now crash the app with a message:

App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.

The window scenes and statusBarManager's really only give us access to frame - if this is still possible, I am not aware how.

#Swift, iOS10-12:

The following works for me, and after profiling all the methods for capturing programmatic screenshots - this is the quickest, and the recommended way from Apple following iOS 10

let screenshotSize = CGSize(width: UIScreen.main.bounds.width * 0.6, height: UIScreen.main.bounds.height * 0.6) let renderer = UIGraphicsImageRenderer(size: screenshotSize) let statusBar = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow let screenshot = renderer.image { _ in UIApplication.shared.keyWindow?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) statusBar?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) } 

You don't have to scale your screenshot size down (you can use UIScreen.main.bounds directly if you want)

#Swift, iOS10+:

The following works for me, and after profiling all the methods for capturing programmatic screenshots - this is the quickest, and the recommended way from Apple following iOS 10

let screenshotSize = CGSize(width: UIScreen.main.bounds.width * 0.6, height: UIScreen.main.bounds.height * 0.6) let renderer = UIGraphicsImageRenderer(size: screenshotSize) let statusBar = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow let screenshot = renderer.image { _ in UIApplication.shared.keyWindow?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) statusBar?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) } 

You don't have to scale your screenshot size down (you can use UIScreen.main.bounds directly if you want)

#Swift, iOS 13:

The code below (and other ways of accessing) will now crash the app with a message:

App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.

The window scenes and statusBarManager's really only give us access to frame - if this is still possible, I am not aware how.

#Swift, iOS10-12:

The following works for me, and after profiling all the methods for capturing programmatic screenshots - this is the quickest, and the recommended way from Apple following iOS 10

let screenshotSize = CGSize(width: UIScreen.main.bounds.width * 0.6, height: UIScreen.main.bounds.height * 0.6) let renderer = UIGraphicsImageRenderer(size: screenshotSize) let statusBar = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow let screenshot = renderer.image { _ in UIApplication.shared.keyWindow?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) statusBar?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) } 

You don't have to scale your screenshot size down (you can use UIScreen.main.bounds directly if you want)

Source Link
gadu
  • 1.8k
  • 1
  • 18
  • 32

#Swift, iOS10+:

The following works for me, and after profiling all the methods for capturing programmatic screenshots - this is the quickest, and the recommended way from Apple following iOS 10

let screenshotSize = CGSize(width: UIScreen.main.bounds.width * 0.6, height: UIScreen.main.bounds.height * 0.6) let renderer = UIGraphicsImageRenderer(size: screenshotSize) let statusBar = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow let screenshot = renderer.image { _ in UIApplication.shared.keyWindow?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) statusBar?.drawHierarchy(in: CGRect(origin: .zero, size: screenshotSize), afterScreenUpdates: true) } 

You don't have to scale your screenshot size down (you can use UIScreen.main.bounds directly if you want)