Help us understand the problem. What is going on with this article?


More than 3 years have passed since last update.



YosemiteからQuick Time PlayerのMovie RecordingでiPhone画面を表示できるようになったのでそれを使う。

- (CGImageRef)getIPhoneScreenshot {

    CGWindowID windowID = [self getMovieRecordingWindowID];

    CGWindowImageOption imageOptions = kCGWindowImageDefault;
    CGWindowListOption singleWindowListOptions = kCGWindowListOptionIncludingWindow;
    CGRect imageBounds = CGRectNull;

    return CGWindowListCreateImage(imageBounds, singleWindowListOptions, windowID, imageOptions);

- (CGWindowID)getMovieRecordingWindowID {

    CGWindowListOption windowListOption = kCGWindowListOptionAll | kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;
    CFArrayRef windowList = CGWindowListCopyWindowInfo(windowListOption, kCGNullWindowID);

    NSInteger listCount = CFArrayGetCount(windowList);

    for (CFIndex i = 0; i < listCount; i++) {

        CFDictionaryRef windowInfo = CFArrayGetValueAtIndex(windowList, i);

        CGWindowID windowID = 0;
        CFNumberGetValue(CFDictionaryGetValue(windowInfo, kCGWindowNumber), kCGWindowIDCFNumberType, &windowID);

        CFStringRef windowName = CFDictionaryGetValue(windowInfo, kCGWindowName);

        if ([(__bridge NSString *)windowName isEqualToString:@"Movie Recording"]) {
            return windowID;
    return 0;




Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away