iOS 13 Image Capture API for accessing external camera's filesystem?

后端 未结 1 464
慢半拍i
慢半拍i 2021-02-15 09:31

In Apple\'s iOS 13 feature list page they have the following blurb:

Image Capture API

The Image Capture API allows developers

相关标签:
1条回答
  • 2021-02-15 09:53

    You're looking for the ImageCaptureCore framework. This is the same framework that exists on macOS for importing from SD Cards and Cameras. It is now available in iOS 13.2.

    Update:

    The ImageCaptureCore API is now working as of iOS 13.2.

    However, be warned that as of iOS/iPadOS 13.1 Beta 3 (17A5837a) I have not been able to get it working yet (reported to Apple FB6799036). It is now listed with an asterisk on the iPadOS Features page indicating that it will be "Coming later this year".

    I'm able to start an ICDeviceBrowser, but I see permissions errors when a device is connected and don't get any delegate messages. So there may be some permission or entitlement that is needed before it starts working.

    Unfortunately there is no documentation or sample code (even for macOS) on Apple's developer site. But the framework does exist in the iOS 13 SDK and you can look at the header files there.

    We use this framework in our macOS app and using just the headers to figure things out isn't too bad. You'd start by creating an ICDeviceBrowser (ICDeviceBrowser.h), setting its delegate, and then starting the browser:

    @interface CameraManager() : NSObject <ICDeviceBrowserDelegate>
    {
        ICDeviceBrowser* _deviceBrowser;
    }
    @end
    
    @implementation CameraManager
    - (id) init
    {
        self = [super init];
        _deviceBrowser = [[ICDeviceBrowser alloc] init];
        _deviceBrowser.delegate = self;
        [_deviceBrowser start];
    
        return self;
    }
    ...
    @end
    

    You should then start receiving delegate messages when a camera device is connected:

    - (void)deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing;
    - (void)deviceBrowser:(ICDeviceBrowser*)browser didRemoveDevice:(ICDevice*)removedDevice moreGoing:(BOOL)moreGoing;
    

    When you get a didAddDevice: message you'll then want to use the ICDevice (ICDevice.h) and ICCameraDevice (ICCameraDevice.h) APIs to set a delegate and start a session. Once the session has started you'll start receiving delegate messages:

    - (void)deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing
    {
        if ((addedDevice.type & ICDeviceTypeMaskCamera) == ICDeviceTypeCamera)
        {
            ICCameraDevice* camera = (ICCameraDevice *) addedDevice;
            camera.delegate = self;
            [camera requestOpenSession];
            //  probably want to save 'camera' to a member variable
        }
    }
    

    You can use the delegate method:

    - (void)cameraDevice:(nonnull ICCameraDevice *)camera
             didAddItems:(nonnull NSArray<ICCameraItem *> *)items;
    

    To get a list of items as they are enumerated by the API or wait for:

    - (void)deviceDidBecomeReadyWithCompleteContentCatalog:(ICDevice*)device;
    

    And then use the .contents property on the ICCameraDevice to get all of the contents.

    From there you can use the ICCameraDevice to request thumbnails, metadata, and to download specific files. I'll leave that as an exercise to the reader.

    As I mentioned above this doesn't seem to be working in iOS/iPadOS 13.1 Beta 3. Hopefully this will all start working soon as I'd really like to start testing it myself.

    This is now working in iOS 13.2.

    0 讨论(0)
提交回复
热议问题