user3355723
user3355723

Reputation: 235

Taking screenshot only attaches white image in iOS 8 Using UIGraphicsGetImageFromCurrentImageContext

in iOS 6 & 7 this works fine, but in iOS 8 it takes a screenshot of a white screen when I attach the image.

Oddly, if I cancel, then retry, it works fine..

This is the code;

   [savingPhotoAlert dismissWithClickedButtonIndex:0   animated:YES];

    UIGraphicsBeginImageContext(self.view.bounds.size);

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

Upvotes: 0

Views: 683

Answers (1)

Idali
Idali

Reputation: 1023

What do you cancel? is it a kind of alertView? you have to specify when taking the screenshot(afterScreenUpdates= YES).

- (UIImage *) screenshot {
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);

    [self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

Upvotes: 2

Related Questions