LoginSignup
8
8

More than 5 years have passed since last update.

アプリのスクリーンショットを取得する

Last updated at Posted at 2016-01-20

下のスニペットでメインスクリーンのスクリーンショットが撮影できる。
アプリが複数の UIWindow を保持していたり、複数の UIScreen にまたがってUIが表示されるとしても対応可能なはず。

    UIGraphicsBeginImageContext(_screenSize);
    UIScreen *mainScreen = [UIScreen mainScreen];
    for (UIWindow *windowItr in [UIApplication sharedApplication].windows) {
        if ([windowItr.screen isEqual:mainScreen]) {
            [windowItr drawViewHierarchyInRect:windowItr.frame afterScreenUpdates:YES];
        }
    }
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8