natsuk4ze / gal

How to Save Image or Video to Photo Gallery in Flutter
https://pub.dev/packages/gal
BSD 3-Clause "New" or "Revised" License
105 stars 16 forks source link

Issue with gal Plugin Integration with Flutter Work Manager in IOS #227

Open Hajrakhan opened 3 months ago

Hajrakhan commented 3 months ago

Did you check the documentation and it did not help?

Overview

When using the gal plugin to save images to the device's gallery within a background task scheduled by Flutter Work Manager on iOS, the operation fails with a MissingPluginException for the requestAccess method of the gal plugin.

Error saving image 3: MissingPluginException(No implementation found for method requestAccess on channel gal)

Steps to reproduce

  1. Implement a Flutter application with both Flutter Work Manager and the gal plugin dependencies.
  2. Schedule a background task using Flutter Work Manager that involves saving images to the gallery using the gal plugin.
  3. Execute the background task on an iOS device.
  4. Observe the task failure due to a MissingPluginException related to gal plugin's requestAccess method.

Code sample

Future downloadImagesIOS(bookingId, token) async { PhotovaultBackend photovaultBackend = PhotovaultBackend(); //download list of images dropboxFile = await photovaultBackend.getPictures(bookingId, token: token); var dio = Dio(); for (int i = 0; i < dropboxFile.length; i++) { try { var response = await dio.get(dropboxFile[i].file!, options: Options(responseType: ResponseType.bytes)); try { Uint8List imageData = Uint8List.fromList(response.data); await Gal.putImageBytes(imageData); } catch (e) { print('Error saving image $i: $e'); } } catch (e, stackTrace) { print("Error saving image: $e"); } } }

Environment

Flutter (Channel stable, 3.19.4, on macOS 13.6 22G120 darwin-x64, locale en-PK) • Flutter version 3.19.4 on channel stable at /Users/apple/Documents/FlutterDev/sdk/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 68bfaea224 (3 months ago), 2024-03-20 15:36:31 -0700 • Engine revision a5c24f538d • Dart version 3.3.2 • DevTools version 2.31.1

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

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1) • 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.7+0-17.0.7b1000.6-10550314)

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

[✓] VS Code (version 1.82.2) • VS Code at /Users/apple/Downloads/Visual Studio Code.app/Contents • Flutter extension version 3.90.0

[✓] Connected device (3 available) • iPhone SE (3rd generation) (mobile) • 2785EBB4-ABF1-433D-B0EB-83AF0041B631 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)

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

Logs

Logs ```console [Paste your logs here] ```
natsuk4ze commented 3 months ago

Does this error occur even with permissions granted?

thiparpahnj commented 3 months ago

I ran flutter clean and restarted the simulator, which solved the MissingPluginException error. Hope this helps!

Hajrakhan commented 3 months ago

Does this error occur even with permissions granted?

yes this issue still occurs if permission is granted

natsuk4ze commented 3 months ago

It does not appear that iOS allows saving photos in the background. There is nothing I can work on at this time, but I may be able to work on it when more information comes to light.