iOS 13 Image Capture API是否可以访问外部相机的文件系统? [英] iOS 13 Image Capture API for accessing external camera's filesystem?

查看:176
本文介绍了iOS 13 Image Capture API是否可以访问外部相机的文件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple的iOS 13功能列表页面中,它们具有以下内容脱口秀:

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

图像捕获API

Image Capture API允许开发人员利用Camera 连接工具包,可将照片直接导入他们的应用程序.

The Image Capture API allows developers to leverage the Camera Connection Kit to import photos directly into their apps.

我一直在寻找,但似乎找不到有关此更改及其在API中的位置的任何实际文档.我还记得在WWDC 19的主题演讲/工会状态中听到过一两秒钟的谈论,但是到目前为止,我仍未在任何会议上看到任何细节.

I've been looking but I can't seem to find any actual documentation about this change, and where it exists in the API. I also remember hearing a second or two talk about it in the keynote/state of the union in WWDC 19, but again no details in any session I've found so far.

似乎您可以将相机或其SD卡插入iOS设备上的USB-C/Lightning端口,并能够从第三方应用程序中访问它.我知道您可以导入系统照片库,但是已经存在了很多年.我也了解MiFi硬件的ExternalAccessory框架,但是我没有看到任何重大变化,而且似乎没有公开所描述的功能.

It seems like you would be able to plug in a camera or it's SD card to the USB-C/Lightning port on the iOS device and be able to access that from within a 3rd party app. I know you can import to the system photo library, but that has been around for years. I also know about ExternalAccessory framework for MiFi hardware, but I don't see any significant changes to that, and it doesn't seem to have the described functionality exposed.

我确实看到可以显示UIDocumentPicker,并且它允许用户选择连接的USB设备上的位置.虽然可以,但是如果用户未选择有效的相机位置,则它不是特定于相机的,并且很容易出错.

I do see that UIDocumentPicker can be shown and it allows the user to select a location that may be on a connected USB device. While that could work, it's not camera specific and would be quite error prone, if the user doesn't select a valid camera location.

有人知道我在哪里可以找到有关此更改的更多信息,或者如何以编程方式访问相机的文件系统?该相机将具有标准的相机文件夹结构DCIM和其他内容,因此许多Mac应用程序将其识别为相机文件系统.

Anybody know where I can find more info about this change or how you can programmatically access the camera's filesystem? The camera will have the standard camera folder structure DCIM and stuff, so it is recognized as a camera filesystem by many Mac apps.

推荐答案

您正在寻找ImageCaptureCore框架.这与macOS上用于从SD卡和相机导入的框架相同.现在在iOS 13.2中可用.

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.

更新:

ImageCaptureCore API现在从iOS 13.2开始运行.

The ImageCaptureCore API is now working as of iOS 13.2.

但是,请注意,自iOS/iPadOS 13.1 Beta 3(17A5837a)起,我还无法使其正常运行(报告为Apple FB6799036).现在,它在 iPad OS功能页面上以星号列出,表明它将今年晚些时候来".

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".

我可以启动ICDeviceBrowser,但是在连接设备并且没有收到任何委托消息时,我看到权限错误.因此,在开始工作之前,可能需要一些许可或权利.

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.

不幸的是,Apple的开发人员站点上没有文档或示例代码(即使对于macOS也是如此).但是该框架确实存在于iOS 13 SDK中,您可以在其中查看头文件.

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.

我们在macOS应用程序中使用了此框架,仅使用标头来确定问题还算不错.首先,创建一个ICDeviceBrowser(ICDeviceBrowser.h),设置其委托,然后启动浏览器:

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;

当收到didAddDevice:消息时,您将要使用ICDevice(ICDevice.h)和ICCameraDevice(ICCameraDevice.h)API来设置委托并启动会话.会话开始后,您将开始接收委托消息:

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
    }
}

您可以使用委托方法:

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

要获取API枚举的项目列表,或等待:

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

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

,然后使用ICCameraDevice上的.contents属性获取所有内容.

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

您可以在其中使用ICCameraDevice请求缩略图,元数据以及下载特定文件.我将其留给读者练习.

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.

如上所述,这似乎不适用于iOS/iPadOS 13.1 Beta3.希望所有这些都能尽快开始工作,因为我真的想自己对其进行测试.

现在可以在iOS 13.2中使用了.

This is now working in iOS 13.2.

这篇关于iOS 13 Image Capture API是否可以访问外部相机的文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆