我正在尝试在我的应用程序中实现一个将记录屏幕的功能。我在一些示例代码和 WWDC 2012 视频中找到了一些代码。
到目前为止,我有这个。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Get a list of displays. Copied from working apple source code.
[self getDisplayList];
DisplayRegistrationCallBackSuccessful = NO;
// Register the event for modifying displays.
CGError err = CGDisplayRegisterReconfigurationCallback(DisplayRegisterReconfigurationCallback, NULL);
if (err == kCGErrorSuccess) {
DisplayRegistrationCallBackSuccessful = YES;
}
// Insert code here to initialize your application
const void *keys[1] = { kCGDisplayStreamSourceRect };
const void *values[1] = { CGRectCreateDictionaryRepresentation(CGRectMake(0, 0, 100, 100)) };
CFDictionaryRef properties = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
stream = CGDisplayStreamCreate(displays[0], 100, 100, '420f', properties,
^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {
NSLog(@"Next Frame"); // This line is never called.
});
runLoop = CGDisplayStreamGetRunLoopSource(stream);
CGError err = CGDisplayStreamStart(stream);
if (err == CGDisplayNoErr) {
NSLog(@"Works");
} else {
NSLog(@"Error: %d", err);
}
}
我遇到的问题是 DisplayStream 的回调块没有被调用。我没有收到任何错误或警告。有什么我遗漏的或者我做错了什么吗?