使用避雷线从 OSX cocoa 应用程序录制 iOS 设备的屏幕

Recording an iOS device's screen from an OSX cocoa app with a lightning cable

可以在 Quicktime 中使用新电影录制 > 相机下拉菜单 > select iOS 设备。 AppShow and Screenflow 两者都做到了。

我试过了

Applescript

tell application "QuickTime Player"
set myrec to new movie recording
  tell myrec
      set current camera to video recording device named "Morten's iPod touch"
  end tell
end tell

但这给了我

error "QuickTime Player got an error: Can’t set video recording device \"Morten's iPod touch\" of document \"Movie Recording\" to video recording device named \"Morten's iPod touch\" of document \"Movie Recording\"." number -10006 from video recording device "Morten's iPod touch" of document "Movie Recording"

AVFoundation 由于 iOS 设备在 Quicktime 中显示为相机,我认为它是 AVFoundation 中的捕获设备,但是此代码

for device in AVCaptureDevice.devices() {
    println(device)
}

给我我的 Facetime 高清摄像头和麦克风。

您必须选择加入才能在您的 OS X 应用程序中查看 iOS 屏幕设备。

参见“How do I set up a mirroring session between iOS 8 and Yosemite?

CMIOObjectPropertyAddress   prop    = {
    kCMIOHardwarePropertyAllowScreenCaptureDevices,
    kCMIOObjectPropertyScopeGlobal,
    kCMIOObjectPropertyElementMaster
};
UInt32                      allow   = 1;

CMIOObjectSetPropertyData(kCMIOObjectSystemObject, &prop, 0, NULL, sizeof(allow), &allow);

您可以使用以下方法获取设备列表:

NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
var property = CMIOObjectPropertyAddress(mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyAllowScreenCaptureDevices), mScope: CMIOObjectPropertyScope(kCMIOObjectPropertyScopeGlobal), mElement: CMIOObjectPropertyElement(kCMIOObjectPropertyElementMaster))
var allow : UInt32 = 1
let sizeOfAllow = MemoryLayout<UInt32>.size
CMIOObjectSetPropertyData(CMIOObjectID(kCMIOObjectSystemObject), &property, 0, nil, UInt32(sizeOfAllow), &allow)