flutter_photo_manager icon indicating copy to clipboard operation
flutter_photo_manager copied to clipboard

[Bug report] progressHandler not sending progress value when loading file in shared album.

Open ycwu0609 opened this issue 1 year ago • 2 comments

Version

3.2.0

Platforms

iOS

Device Model

iPhone 15 Pro (iOS 17.5.1)

flutter info

[✓] Flutter (Channel stable, 3.13.9, on macOS 14.3.1 23D60 darwin-arm64, locale zh-Hant-TW)
    • Flutter version 3.13.9 on channel stable at /Users/yc/fvm/versions/3.13.9
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (8 months ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/yc/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.2

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.89.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.90.0

[✓] Connected device (1 available)
    • WinnieYC_iPhone (mobile) • 00008130-00126D802288001C • ios • iOS 17.5.1 21F90

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

How to reproduce?

  1. Enter asset picker.
  2. Select a shared album (which can shared with other users)
  3. Select a video which was not picked before
  4. Use entity.loadFile(progressHandler: progressHandler, isOrigin: true)

At first, progressHandler would receive the event {state: prepare, progress: 0.0}. Then, progressHandler couldn't get any events. I've observed the code, the iOS code did not send the progress events. Also, when the iOS code sending success/failed event, Flutter isn't received the message sometimes.

It seems familiar with #679

Logs

nativeIOS: progress {
    progress = 0;
    state = 0;
} --------- printed by native iOS in notify function (PMProgressHandler.m)
flutter: D/2024-06-27 12:07:29.936918 [35130] state PMRequestState.prepare, progress: 0.0

nativeIOS: progress {
    progress = 1;
    state = 2;
}
**Not Received from Flutter**

Example code (optional)

final progressHandler = PMProgressHandler();
progressHandler.stream.listen((event) {
  Log.d("state ${event.state}, progress: ${event.progress}");
  if (event.state == PMRequestState.success) {
    if (!completer.isCompleted) {
      completer.complete(true);
    }
  } else if (event.state == PMRequestState.failed) {
    if (!completer.isCompleted) {
      completer.complete(false);
    }
  } else {
    progressNotifier.value = event.progress;
    if (progressNotifier.value >= 1.0) {
      if (!completer.isCompleted) {
        completer.complete(true);
      }
    }
  }
});
entity.loadFile(progressHandler: progressHandler, isOrigin: true);

Contact

No response

ycwu0609 avatar Jun 27 '24 06:06 ycwu0609

I face same issue, my photo_manager is 2.8.1. download progress no update.

dodatw avatar Jun 27 '24 07:06 dodatw

Also, when the iOS code sending success/failed event, Flutter isn't received the message sometimes.

I face the same issue, the progress is always at 99%.

I think the problem is the invoke code in the PMProgressHandler

- (void)notify:(double)progress state:(PMProgressState)state {
    int s = state;
    NSDictionary *dict = @{
        @"state": @(s),
        @"progress": @(progress),
    };

    if (channel) {
        // Here's the problem, the `invokeMethod` runs in the next runloop, and the channel is already set to nil.
        dispatch_async(dispatch_get_main_queue(), ^{
            [channel invokeMethod:@"notifyProgress" arguments:dict];
        });
    }

}

- (void)register:(NSObject <FlutterPluginRegistrar> *)registrar channelIndex:(int)index {
    NSString *name = [NSString stringWithFormat:@"com.fluttercandies/photo_manager/progress/%d", index];
    channel = [FlutterMethodChannel methodChannelWithName:name binaryMessenger:registrar.messenger];
}

- (void)deinit {
    // deinit method runs before the last [channel invokeMethod:] called.
    channel = nil;
}

Swag-Tristan avatar Jun 28 '24 03:06 Swag-Tristan

Thanks for the fix; the download task can now complete successfully. However, there is still no returned progress value when downloading items in a shared album. (Only return 0.0 and 1.0)

ycwu0609 avatar Aug 27 '24 01:08 ycwu0609

Thanks for the feedback. Labeling for further investigation.

AlexV525 avatar Aug 27 '24 02:08 AlexV525

Tested with both images and videos from a shared album. Unfortunately, the progress handler only reports 0 and 1 during the whole process which doesn't seem to be our implementation issue. @ycwu0609 Could you provide a case where shared album assets can report correct progress during fetching from the iCloud? If not, I guess there is nothing we can do.

AlexV525 avatar Sep 15 '24 17:09 AlexV525

Closing as the above discussion.

AlexV525 avatar Sep 26 '24 03:09 AlexV525