[Solved] How do I capture screen view and share it? [closed]


You can add share button

var shareButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: "shareButtonPressed:")
self.navigationItem.rightBarButtonItem = shareButton

and populate share options

func shareButtonPressed(sender: AnyObject) {
    NSLog("shareButton pressed")
    let stringtoshare: String = "This is a string to share"

    //add current screen shot image to share
    let imagetoshare = captureScreen()

    let activityItems: [AnyObject] = [stringtoshare, imagetoshare]
    let activityVC: UIActivityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
    activityVC.excludedActivityTypes = [UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypePostToFacebook, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo]
    self.presentViewController(activityVC, animated: TRUE, completion: { _ in })
}

//Capture screen shot image

func captureScreen() -> UIImage
{

    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, false, 0);

    self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)

    var image:UIImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image
}

Please let me know if you find any trouble in this, I am not able to test this code snip (as I am not at system) but this is how i used to handle in apps.

9

solved How do I capture screen view and share it? [closed]