Take a screenshot and print it XCODE
I'm trying to take a screenshot and print it right away. For some reason it doesn't response right...
I'm saving the screenshot into documents directory. Here is the code:

    -(IBAction)printdoc
{
    
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
    else
        UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
    NSData * imageData = UIImageJPEGRepresentation(viewImage, 1.0);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.jpg"];
    [imageData writeToFile:documentsDirectory atomically:YES];
    NSString *myFilePath = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.jpg"];
    NSData *myData = [NSData dataWithContentsOfFile:myFilePath];

    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    if  (pic && [UIPrintInteractionController canPrintData:myData] ) {
        pic.delegate = self;
        NSLog(@"CAN PRINT !!!!!!!!!!!!");
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = [myFilePath lastPathComponent];
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
        pic.printingItem = myData;
        
        void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
        ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
            
            if (!completed && error)
                NSLog(@"FAILED! due to error in domain %@ with error code %u",
                      error.domain, error.code);
        };
        // iPad only printing
        
   
            [pic presentAnimated:YES completionHandler:completionHandler];
        
    }}

Take a screenshot and print it XCODE
===

I'm trying to take a screenshot and print it right away. For some reason it doesn't response right...
I'm saving the screenshot into documents directory. Here is the code:

    -(IBAction)printdoc
{
    
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
    else
        UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
    NSData * imageData = UIImageJPEGRepresentation(viewImage, 1.0);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.jpg"];
    [imageData writeToFile:documentsDirectory atomically:YES];
    NSString *myFilePath = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.jpg"];
    NSData *myData = [NSData dataWithContentsOfFile:myFilePath];

    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    if  (pic && [UIPrintInteractionController canPrintData:myData] ) {
        pic.delegate = self;
        NSLog(@"CAN PRINT !!!!!!!!!!!!");
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = [myFilePath lastPathComponent];
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
        pic.printingItem = myData;
        
        void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
        ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
            
            if (!completed && error)
                NSLog(@"FAILED! due to error in domain %@ with error code %u",
                      error.domain, error.code);
        };
        // iPad only printing
        
   
            [pic presentAnimated:YES completionHandler:completionHandler];
        
    }}
