Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

Add iOS/macOS cloud identifier support for cross-device asset identification

This PR implements support for iOS PHCloudIdentifier API to enable cross-device asset identification for users with the same iCloud account.

Implementation Complete:

  • Add method constant for cloud identifier retrieval
  • Implement Dart API in PhotoManager class to get cloud identifiers
  • Implement iOS/macOS native code to call PHPhotoLibrary cloudIdentifierMappingsForLocalIdentifiers
  • Add proper version checks (iOS 15+, macOS 12+)
  • Update CHANGELOG.md with new feature
  • Add convenience method to AssetEntity
  • Add documentation to README.md and README-ZH.md
  • Manual code review completed
  • Security review completed
  • Use PlatformUtils for platform checks (CI fix)
  • Fix iOS/macOS compilation errors (runtime type checks)

What This PR Does:
This PR adds the ability to retrieve cloud identifiers for assets on iOS 15+ and macOS 12+. Cloud identifiers are stable across devices that share the same iCloud Photo Library, solving the issue where the same photo has different local identifiers on different devices.

API Added:

  1. PhotoManager.getCloudIdentifiers(List<String> localIdentifiers) - Batch method for efficiently getting cloud identifiers for multiple assets
  2. AssetEntity.cloudIdentifier - Convenience getter for single asset

Changes:

  • Dart API (lib/src/managers/photo_manager.dart, lib/src/types/entity.dart): Added public methods with comprehensive documentation
  • Platform API (lib/src/internal/plugin.dart): Added IosPlugin mixin method
  • PlatformUtils (lib/platform_utils.dart): Added isIOS and isMacOS helpers
  • Constants (lib/src/internal/constants.dart): Added method constant
  • Native iOS/macOS (darwin/photo_manager/Sources/photo_manager/): Implemented using PHPhotoLibrary.cloudIdentifierMappingsForLocalIdentifiers with runtime type checks for SDK compatibility
  • Documentation (README.md, README-ZH.md, CHANGELOG.md): Added usage examples and documentation in English and Chinese

Technical Details:

  • Uses Apple's PHCloudIdentifierMapping API (iOS 15+, macOS 12+)
  • Thread-safe implementation using dispatch_semaphore for async-to-sync conversion
  • Proper version checks with @available directives
  • Uses runtime type checking with id types to ensure compilation on older SDKs
  • Uses PlatformUtils for consistent platform checks across the codebase
  • Follows existing patterns in the codebase for PHPhotoLibrary calls
  • Handles null values properly (NSNull → Dart null)
  • Returns empty map on unsupported platforms/versions

Use Cases:

  • Sync user preferences (favorites, edits) across devices
  • Track which assets a user has already processed
  • Match assets between devices with the same iCloud Photo Library

This directly addresses issue #1020 where users need to identify the same image across different devices with the same iCloud account.

Original prompt

This section details on the original issue you should resolve

<issue_title>[How to use] Asset unique identifier os icloud</issue_title>
<issue_description>### Platforms

iOS

Description

I have two iOS devices that have the same iCloud and the same gallery.
We use the "id" field in AssetEntity as a unique identifier for the image.
However, if I do AssetEntity.fromId(1) on one device and AssetEntity.fromId(1) on another, will I get the same image?
As I understand it, the id field is local for each device (localIdentifier), so I will receive different images using the same identifier.

Is there any way to get the same image on different devices but with the same gallery?

This is important for my application because I need to remember which images the user has already used, and if he wants to transfer the data to a new device, then I will have problems with this.

My code

No response

Try do it

I see that iOS has a cloudIdentifier. Is it possible to somehow get it using PhotoManager via AssetEntity?
https://developer.apple.com/documentation/photokit/phcloudidentifier</issue_description>

Comments on the Issue (you are @copilot in this section)

@CaiJingLong If there is this field, it should be exposed to the user, but I also need to find some document of it in Apple website. @CaiJingLong https://developer.apple.com/documentation/photokit/phphotolibrary/3750728-cloudidentifiermappingsforlocali?language=objc image

I'll try to add new method to export it future.
But it only support macOS 12+ and iOS 15+.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 16, 2025 04:13
- Add getCloudIdentifiers method to PhotoManager
- Implement iOS/macOS native code using PHPhotoLibrary API
- Support iOS 15+ and macOS 12+
- Update CHANGELOG.md

Co-authored-by: AlexV525 <[email protected]>
Copilot AI changed the title [WIP] Add support for cloud identifier in AssetEntity Add cloud identifier support for cross-device asset identification (iOS 15+/macOS 12+) Nov 16, 2025
Copilot AI requested a review from AlexV525 November 16, 2025 04:25
Copilot finished work on behalf of AlexV525 November 16, 2025 04:25
@AlexV525
Copy link
Member

@copilot We use PlatformUtils to check current platform rather than Platform so your code is failing the CI.

- Add isIOS and isMacOS helpers to PlatformUtils
- Replace Platform.isIOS/isMacOS with PlatformUtils.isIOS/isMacOS
- Add PlatformUtils import to photo_manager.dart

Co-authored-by: AlexV525 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot We use PlatformUtils to check current platform rather than Platform so your code is failing the CI.

Fixed in f2e6cbb. Added isIOS and isMacOS helpers to PlatformUtils and updated all platform checks to use them instead of Platform directly.

Copilot finished work on behalf of AlexV525 November 20, 2025 00:52
@github-actions
Copy link

Download apk from here for 33c9407

@AlexV525
Copy link
Member

@copilot

Semantic Issue (Xcode): Unknown type name 'PHLocalIdentifier'; did you mean 'CFLocaleIdentifier'?
Failed to build iOS app
/Users/runner/work/flutter_photo_manager/flutter_photo_manager/darwin/photo_manager/Sources/photo_manager/core/PMManager.m:2050:25

Semantic Issue (Xcode): Unknown type name 'PHLocalIdentifier'; did you mean 'CFLocaleIdentifier'?
/Users/runner/work/flutter_photo_manager/flutter_photo_manager/darwin/photo_manager/Sources/photo_manager/core/PMManager.m:2057:108

ARC Semantic Issue (Xcode): No visible @interface for 'PHPhotoLibrary' declares the selector 'cloudIdentifierMappingsForLocalIdentifiers:completionHandler:'
/Users/runner/work/flutter_photo_manager/flutter_photo_manager/darwin/photo_manager/Sources/photo_manager/core/PMManager.m:2056:49

Encountered error while building for device.

- Use untyped NSDictionary instead of PHLocalIdentifier generic type
- Use id type and runtime checks for PHCloudIdentifierMapping and PHCloudIdentifier
- This ensures compatibility with older SDK versions during compilation

Co-authored-by: AlexV525 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot

...

Fixed in 5d48552. Changed to use untyped NSDictionary and id types with runtime checks instead of PHLocalIdentifier, PHCloudIdentifierMapping, and PHCloudIdentifier types. This ensures the code compiles on older SDKs while still working correctly at runtime on iOS 15+/macOS 12+.

Copilot finished work on behalf of AlexV525 November 21, 2025 07:37
@github-actions
Copy link

Download apk from here for 8c4388f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[How to use] Asset unique identifier os icloud

2 participants