如何从MacOS的图片库中获取所有PHAsset [英] How to get all PHAssets from MacOS's Photo Library

查看:159
本文介绍了如何从MacOS的图片库中获取所有PHAsset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 PHAsset .但是,我发现的所有示例仅适用于iOS,如以下示例所示,其中检索资产的最后一行在macos框架上不可用:

I want to parse all images from my MacOS Photos Library, using PHAsset. However all examples I find are only working for iOS, like the one below, where the last line, which retrieves the assets is not available on macos framework:

    NSMutableArray *photos = [[NSMutableArray alloc] init];
    PHFetchOptions *allPhotosOptions = [[PHFetchOptions alloc] init];
    allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];

 // Below compilation error as fetchAssetsWithMediaType is only on iOS framework
    PHFetchResult *allPhotos = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosOptions];

我应该在MacOS(版本10.13)上使用什么fetchAssets命令,或者还有另一种方法?

What fetchAssets command should I use on MacOS (version 10.13), or is there another way to do so ?

推荐答案

Photos框架-或至少是该框架的主要子集(可为应用程序提供对整个Photos库的读/写访问权限)-在macOS.

The Photos framework — or at least, the main subset of that framework, which provides apps with read/write access to the entire Photos library — is not available in macOS.

照片和PhotosUI存在于macOS中,但仅用于支持特定的应用程序扩展功能:

Photos and PhotosUI are present in macOS, but only in support of specific app-extension features:

  • 照片编辑扩展.用户在编辑"模式下针对单个资产从照片"应用调用这些资源,并且可以直接访问该资产的照片/视频数据,因此它甚至不使用PHAsset类.
  • 照片项目扩展名.这些涉及资产的收集并为每个资产有选择地加载数据,因此存在更多的PHAsset/PHImageManager系统.但是,与iOS(仅是项目扩展所需的内容,例如获取该项目中的资产)相比,它的子集仍然较少,并且仅适用于应用扩展,而不能用于独立应用.
  • Photo Editing extensions. The user invokes these from the Photos app while in Edit mode for a single asset, and it provides direct access to the photo/video data for that asset, so it doesn’t even use the PHAsset class.
  • Photo Project extensions. These involve collections of assets and selectively loading data for each, so more of the PHAsset/PHImageManager system is present. However, it’s still a reduced subset compared to iOS (only what’s needed for a project extension, like fetching the assets in that project), and it’s accessible only to app extensions, not standalone apps.

如果您想要在macOS上使用完整的Photos框架,最好的选择是向Apple提出功能请求.

If you’d like the full Photos framework on macOS, your best bet is to file a feature request with Apple.

这篇关于如何从MacOS的图片库中获取所有PHAsset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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