Skip to content

Conversation

@alpinnz
Copy link

@alpinnz alpinnz commented Sep 21, 2025

This PR fixes compatibility issues with iOS 26.0 in the flutter_image_compress_common package.
Previously, certain APIs that were deprecated or removed in iOS 26.0 were still being used, causing build errors.

Changes include:

  • Replacing deprecated ALAsset and ALAssetRepresentation with PHAsset from the Photos framework.
  • Updating code to ensure proper functionality on iOS 26.0 and later.
  • Minor code cleanup and improvements to maintain backward compatibility.

This update ensures that the package can now build successfully on iOS 26.0 without introducing breaking changes for older iOS versions.

@CaiJingLong
Copy link
Member

Hi, what is the minimum supported iOS SDK version for this new writing method? What is the minimum supported iOS device version?

@alpinnz
Copy link
Author

alpinnz commented Sep 30, 2025

Hi. The new method is based on PHAsset, which has been available since iOS 8.0.
So technically it works from iOS 8 and above.

That said, Flutter itself now requires iOS 11.0 as the minimum deployment target, so in practice the minimum supported iOS SDK and device version is 11.0.

This update has also been tested to build and run fine on iOS 16+ (iOS 26.0 reference).

Hi, what is the minimum supported iOS SDK version for this new writing method? What is the minimum supported iOS device version?

@AlexV525 AlexV525 requested a review from Copilot October 20, 2025 07:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Migrates iOS metadata handling from the deprecated AssetsLibrary (ALAsset) APIs to the Photos (PHAsset) framework to resolve build issues on newer iOS versions. Also includes minor cleanup and comment updates.

  • Replace ALAsset/ALAssetRepresentation usage with PHAsset and PHImageManager requests
  • Remove ALAsset-based helper methods and add PHAsset-based equivalents
  • Minor comment and spelling fixes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 11 comments.

File Description
packages/flutter_image_compress_common/ios/Classes/SYPictureMetadata/SYMetadata.m Replaces ALAsset metadata extraction with PHImageManager-based extraction; adds PHAsset helpers.
packages/flutter_image_compress_common/ios/Classes/SYPictureMetadata/SYMetadata.h Updates public API to PHAsset-based methods; removes ALAsset references; adjusts comments.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

+ (instancetype)metadataWithDictionary:(NSDictionary *)dictionary;
+ (instancetype)metadataWithAsset:(ALAsset *)asset __TVOS_PROHIBITED;
+ (instancetype)metadataWithAssetURL:(NSURL *)assetURL __TVOS_PROHIBITED;
+ (instancetype)metadataWithPHAsset:(PHAsset *)asset; // Using ALAsset
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renames/removes previously public APIs (+metadataWithAsset: and +dictionaryWithAssetURL:), creating a breaking change contrary to the PR description. To preserve source compatibility, consider reintroducing a deprecated wrapper for +dictionaryWithAssetURL: that fetches a PHAsset via Photos (e.g., using [PHAsset fetchAssetsWithALAssetURLs:options:]) and forwards to +dictionaryWithPHAsset:. If you intentionally drop ALAsset support, please note it clearly as a breaking change.

Copilot uses AI. Check for mistakes.

+ (NSDictionary *)dictionaryWithAssetURL:(NSURL *)assetURL __TVOS_PROHIBITED;
+ (NSDictionary *)dictionaryWithPHAsset:(PHAsset *)asset; // Using ALAssetsLibrary

Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renames/removes previously public APIs (+metadataWithAsset: and +dictionaryWithAssetURL:), creating a breaking change contrary to the PR description. To preserve source compatibility, consider reintroducing a deprecated wrapper for +dictionaryWithAssetURL: that fetches a PHAsset via Photos (e.g., using [PHAsset fetchAssetsWithALAssetURLs:options:]) and forwards to +dictionaryWithPHAsset:. If you intentionally drop ALAsset support, please note it clearly as a breaking change.

Suggested change
// Deprecated: Use dictionaryWithPHAsset: instead. This wrapper fetches PHAsset from ALAsset URL.
+ (NSDictionary *)dictionaryWithAssetURL:(NSURL *)assetURL __attribute__((deprecated("Use dictionaryWithPHAsset: instead.")));

Copilot uses AI. Check for mistakes.
+ (instancetype)metadataWithDictionary:(NSDictionary *)dictionary;
+ (instancetype)metadataWithAsset:(ALAsset *)asset __TVOS_PROHIBITED;
+ (instancetype)metadataWithAssetURL:(NSURL *)assetURL __TVOS_PROHIBITED;
+ (instancetype)metadataWithPHAsset:(PHAsset *)asset; // Using ALAsset
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comments are incorrect: these methods use PHAsset/Photos, not ALAsset/ALAssetsLibrary. Please update the comments to avoid confusion (e.g., 'PHAsset-based' or 'Using Photos framework').

Copilot uses AI. Check for mistakes.
+ (instancetype)metadataWithImageData:(NSData *)imageData;

+ (NSDictionary *)dictionaryWithAssetURL:(NSURL *)assetURL __TVOS_PROHIBITED;
+ (NSDictionary *)dictionaryWithPHAsset:(PHAsset *)asset; // Using ALAssetsLibrary
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comments are incorrect: these methods use PHAsset/Photos, not ALAsset/ALAssetsLibrary. Please update the comments to avoid confusion (e.g., 'PHAsset-based' or 'Using Photos framework').

Copilot uses AI. Check for mistakes.
//

#import <Foundation/Foundation.h>
#import <Photos/Photos.h> // Using Photos framework
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce header coupling and speed up builds, prefer forward-declaring PHAsset in the header and keep the Photos import in the .m file. For example, replace the import with '@Class PHAsset;' here (Photos is already imported in SYMetadata.m).

Suggested change
#import <Photos/Photos.h> // Using Photos framework
@class PHAsset; // Forward declaration to reduce header coupling

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +55
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = YES;
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'options.synchronous = YES' will block the calling thread until the result is ready, which can cause UI jank if invoked on the main thread. Consider an async variant (completion-based API) or enforce off-main-thread usage and document this constraint.

Copilot uses AI. Check for mistakes.
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = YES;
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: enable 'options.networkAccessAllowed = YES' to support iCloud-only assets; otherwise 'imageData' may be nil and no metadata will be returned.

Suggested change
options.synchronous = YES;
options.synchronous = YES;
options.networkAccessAllowed = YES;

Copilot uses AI. Check for mistakes.
Comment on lines +169 to +173
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = YES;

Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method also uses 'options.synchronous = YES', which blocks the caller. Align with the earlier method by using an asynchronous request or ensuring calls are made off the main thread.

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +55
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = YES;
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PHAsset-to-metadata extraction logic is duplicated in both '+metadataWithPHAsset:' and '+dictionaryWithPHAsset:'. Consider extracting a shared helper (e.g., a static method that returns the metadata dictionary) and have both methods call it to reduce duplication and keep behavior consistent.

Copilot uses AI. Check for mistakes.
@property SYMETADATA_PROPERTY_STRONG SYMetadataExifAux *metadataExifAux;

// we don't know how to parse those, so we juste give access to them
// Fallback
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment 'Fallback' is vague compared to the original explanation. Consider clarifying intent (e.g., 'Unparsed vendor-specific dictionaries exposed as-is for consumers').

Suggested change
// Fallback
// Unparsed vendor-specific dictionaries exposed as-is for consumers (fallback for unknown or proprietary metadata)

Copilot uses AI. Check for mistakes.
@AlexV525
Copy link
Member

@alpinnz Sorry for the late review. Could you address the review produced above? You can also find relevant implementations in photo_manager regarding PHAsset.

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.

3 participants