'AVCaptureDevice - iphone/ipad as video source
Can AVCaptureDevice be used (objective-c or Swift) to access an iOS device as a camera source, when it is connected via a lightning cable, very much like Quicktime does for OSX Yosemite?
Quicktime select camera source image
If not, is there any other way to capture it?
I'm using AVCaptureDevice.devices() (in swift) but it only lists the built-in Mac camera and mic.
Solution 1:[1]
Found the solution for this (thanks Chris Adamson), after looking at a presentation on WWDC where Apple announced this capability - fast forward to 4:09.
The following CMI property needs to be set before AVCaptureDevice can detect the iOS device as a camera/capture device (example in Swift):
var prop : CMIOObjectPropertyAddress = CMIOObjectPropertyAddress(
mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyAllowScreenCaptureDevices),
mScope: CMIOObjectPropertyScope(kCMIOObjectPropertyScopeGlobal),
mElement: CMIOObjectPropertyElement(kCMIOObjectPropertyElementMaster))
var allow:UInt32 = 1
CMIOObjectSetPropertyData( CMIOObjectID(kCMIOObjectSystemObject),
&prop,
0,
nil,
UInt32(sizeofValue(allow)),
&allow)
After this is done (e.g. in your AppDelegate), the standard registration of observers can be done, and the iOS camera will show up in the list of available devices
// register for notifications when a new device is connected
notifications.registerObserver(AVCaptureSessionDidStartRunningNotification, forObject: session, block: {note in
var devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeMuxed)
+ AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice]
for device in self.devices {
if device.modelID == "iOS Device" {
// device is your AVCaptureDevice... use it as usual
}
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Glorfindel |