objective-cmacosphotosphasset

How to get all PHAssets from MacOS's Photo Library


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];

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


Solution

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

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

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