1

Below I have tried to code so the screenShot function will take a full screenshot of my viewController. I am trying to figure out how I could take the screenshot and put it in into my activityItems in the sharePressed action, so it will show the screenshot when you try to share.

func captureScreen() -> UIImage? {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.main.scale)
    view.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image
}


@IBAction func sharePressed(_ sender: Any) {

    let activityVC = UIActivityViewController(activityItems: [""], applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = self.view

    self.present(activityVC, animated: true, completion: nil)  
}
Tabj
  • 33
  • 5

1 Answers1

1
@IBAction func sharePressed(_ sender: Any) {

    let imgScreenshot = captureScreen()

    if let imgScreenshot = imgScreenshot {
        let objectsToShare = ["Post message", imgScreenshot] as [Any]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
        activityVC.excludedActivityTypes = [UIActivityType.airDrop, UIActivityType.addToReadingList]
        self.present(activityVC, animated: true, completion: nil)
    }
}
Hooda
  • 1,157
  • 1
  • 9
  • 16